Skip to content

Commit

Permalink
feat(echo --clear): add --clear option to echo (#819)
Browse files Browse the repository at this point in the history
* feat(echo --clear): add --clear option to echo

Signed-off-by: Guillaumebeuzeboc <[email protected]>

* address review comments, and adjust test result check.

Signed-off-by: Tomoya Fujita <[email protected]>

* use escape sequence instead of clear/cls, and remove test.

Signed-off-by: Tomoya Fujita <[email protected]>

---------

Signed-off-by: Guillaumebeuzeboc <[email protected]>
Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Tomoya Fujita <[email protected]>
  • Loading branch information
Guillaumebeuzeboc and fujitatomoya authored Nov 1, 2024
1 parent a3198b8 commit fce8ae7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ros2topic/ros2topic/verb/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def add_arguments(self, parser, cli_name):
parser.add_argument(
'--include-message-info', '-i', action='store_true',
help='Shows the associated message info.')
parser.add_argument(
'--clear', '-c', action='store_true',
help='Clear screen before printing next message')

def choose_qos(self, node, args):

Expand Down Expand Up @@ -185,6 +188,7 @@ def main(self, *, args):
self.no_str = args.no_str
self.flow_style = args.flow_style
self.once = args.once
self.clear_screen = args.clear

self.filter_fn = None
if args.filter_expr:
Expand Down Expand Up @@ -280,6 +284,10 @@ def _subscriber_callback(self, msg, info):
if self.future is not None and self.once:
self.future.set_result(True)

# Clear terminal screen before print
if self.clear_screen:
clear_terminal()

if not hasattr(submsg, '__slots__'):
# raw
if self.include_message_info:
Expand Down Expand Up @@ -322,3 +330,7 @@ def _message_lost_event_callback(message_lost_status):
f'\n\ttotal count: {message_lost_status.total_count}',
end='---\n'
)


def clear_terminal():
print('\x1b[H\x1b[2J')

0 comments on commit fce8ae7

Please sign in to comment.