Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(echo --clear): add --clear option to echo #819

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from

Conversation

Guillaumebeuzeboc
Copy link

@Guillaumebeuzeboc Guillaumebeuzeboc commented Apr 11, 2023

Adds the --clear/-c option to echo.

Solves this issue: #725

This was previously available in ROS.

This clears the screen before a new message is displayed.

ESC[2J corresponds to erase entire screen
ESC[H corresponds to moves cursor to home position (0, 0)

I had to build rolling from source to successfully run the tests

Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_print = '---Got new message, message info:---\n'
to_print = f'{to_print}{info}\n'
to_print = f'{to_print}---Message data:---\n'
print(f'{self.prefix}{to_print}{submsg}', end='\n---\n')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having escape sequence was what we do in ROS 1 rostopic echo, so this would be probably good.

instead, how about taking advantage of os.system() to clear the screen? so that we can just rely on system shell that gives us more flexibility for the future?

import os
import system

if platform.system() == 'Windows':
    os.system('cls')
else:
    os.system('clear')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the escape sequence is potentially problematic, particularly on Windows.

That said, I'm really not to enamored of doing os.system. That almost always leads to trouble down the line, as it is difficult to deal with errors and easy to trick it into doing something nefarious.

I think it is worthwhile here to step back and maybe look at some of the python command-line libraries and see what they do in this situation. If we can find a solution to work on all shells and in Windows (both cmd and powershell), and does not require os.system, that would be the ideal.

@Guillaumebeuzeboc
Copy link
Author

implementation looks good to me but many tests are failing.

could you address the following failures?

https://build.ros2.org/job/Rpr__ros2cli__ubuntu_jammy_amd64/238/testReport/ros2topic.ros2topic.test/test_cli/test_cli/

https://build.ros2.org/job/Rpr__ros2cli__ubuntu_jammy_amd64/238/testReport/ros2topic.ros2topic.test/test_echo_pub/test_echo_pub/

I had the same failure with the HEAD of rolling for this repo. I had to rebuild all rolling from source for them to pass.
I believe the CI is using the debians of rolling right? I pulled all the repo from HEAD.

@clalancette
Copy link
Contributor

I believe the CI is using the debians of rolling right?

Yes, that's correct, though as of yesterday, they are the same thing. That said, these tests have indeed been flaky here for a while, and we haven't had time to track it down. So I wouldn't worry about those two in particular right now.

@clalancette clalancette added more-information-needed Further information is required requires-changes labels Apr 20, 2023
@ahemwe
Copy link

ahemwe commented Jun 29, 2023

Does that PR require further changes?

@clalancette
Copy link
Contributor

Does that PR require further changes?

Yes, we need to come to a conclusion on this discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed Further information is required requires-changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants