From 746e26bf9e218b185783c6d88c0c759e65ee868c Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Wed, 20 Nov 2024 13:27:21 +1300 Subject: [PATCH] listener: clear screen on multiple output I suggest to clear the screen when using the listener with -n. This way the updates don't just scroll by which isn't legible but instead stay in place and update, similar to the top command. --- src/systemcmds/topic_listener/listener_main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/systemcmds/topic_listener/listener_main.cpp b/src/systemcmds/topic_listener/listener_main.cpp index b4db038c12..83ca22ddd7 100644 --- a/src/systemcmds/topic_listener/listener_main.cpp +++ b/src/systemcmds/topic_listener/listener_main.cpp @@ -113,6 +113,9 @@ void listener(const orb_id_t &id, unsigned num_msgs, int topic_instance, fds[1].fd = sub; fds[1].events = POLLIN; + // Clear screen + dprintf(1, "\033[2J\n"); + while (msgs_received < num_msgs) { if (poll(&fds[0], 2, int(MESSAGE_TIMEOUT_S * 1000)) > 0) { @@ -139,6 +142,8 @@ void listener(const orb_id_t &id, unsigned num_msgs, int topic_instance, if (fds[1].revents & POLLIN) { msgs_received++; + // Move cursor to home position + dprintf(1, "\033[H"); PX4_INFO_RAW("\nTOPIC: %s instance %d #%d\n", id->o_name, topic_instance, msgs_received); int ret = listener_print_topic(id, sub);