Add color output utilities and tests#1248
Conversation
|
Tick the box to add this pull request to the merge queue (same as
|
- Add cross-platform ANSI color helpers via colorama. - Support NO_COLOR and FORCE_COLOR env based switch control. - Apply color to ros2node info output as a reference integration. Signed-off-by: Peng Wang <penwang@qti.qualcomm.com>
|
Hi @skyegalaxy, do you have suggestions for this PR? |
|
Hi @fujitatomoya, @kscottz, and @StefanFabian, I've moved the color support work to this PR. Thanks for all the valuable suggestions on #1223. I'd appreciate it if you could take a look and share any additional feedback or suggestions. |
|
Thanks @penww. Just a heads up it takes a week or two to get fresh PRs assigned through our regular meeting. We'll get you a review just as soon as is feasible. |
skyegalaxy
left a comment
There was a problem hiding this comment.
lgtm. had meant to review this a while ago so thank you for your patience!
fujitatomoya
left a comment
There was a problem hiding this comment.
i am not inclined to take this PR especially with colorized default behavior and environmentatl variables.
i believe that with color disabled, everything prints with no escape codes at all, so the terminal renders it in whatever default foreground/background the user configured. that's the maximally safe behavior.
IMO, user's terminal configuration and themes are different and set up as user's preference. this would be problem for some users like blue on black is the notorious case?
and then, affected user needs to opt-out this via environmental variable to disable the colorized behavior from ros2cli.
i would suggest that restricting the palette actually used in commands to theme-safe choices (bold, cyan, green, yellow; avoid blue as primary, never black/white), and consider a --color flag? so that users aren't forced into env-var-only control. besides that, defaulting to off would be the most conservative option, i think.
|
Hi @fujitatomoya, thanks for review. I agree that the default behavior and color choices need to be handled carefully. For the default behavior, one important point is that on ROS Lyrical (Ubuntu 26.04 / Python 3.14), argparse-generated help and usage output is already color-enabled by default when the terminal supports it. Users will already see color in ros2 help/usage output. If command output is default-off while argparse help is default-on, the overall CLI experience can become inconsistent. (https://docs.python.org/3/library/argparse.html#color) For the palette, I agree we should be conservative. The initial colors were chosen to stay visually close to Python argparse's colorized help style, but I understand the concern about specific colors such as blue on some terminal themes (BOLD_BLUE is better). I think the common utility can expose the basic color capabilities, while each command integration should be reviewed separately so the actual palette is conservative and theme-friendly. I also think Python argparse is a useful reference point here. Its color support was added upstream after discussion and review, and it is now the default behavior in Python 3.14. (we can refer: python/cpython#130645)
That said, I do not want to be too strict about default-on behavior. If default-off, or an explicit Please let me know which default policy you would prefer, and I can adjust the PR accordingly. |
i am still inclined to take this path, but let's hear more opinion here. thanks for being constructive, i really appreciate that. |

This is the first PR to introduce colorized output support for ROS 2 commands. Once the approach is aligned on and approved, I will proceed with adding color support to more commands.
Description
Add helpers for supporting color output for ros2cli.
Fixes #1222
No color:

Is this user-facing behavior change?
Yes, the user can see color output as default.
Did you use Generative AI?
Assissted-by: Claude Code (Claude Sonnet 4.6)
Additional Information
NO_COLOR,FORCE_COLORenv spec for CLI: https://no-color.org, https://force-color.org