Skip to content

Add color output utilities and tests#1248

Open
penww wants to merge 1 commit into
ros2:rollingfrom
penww:feat/color_support
Open

Add color output utilities and tests#1248
penww wants to merge 1 commit into
ros2:rollingfrom
penww:feat/color_support

Conversation

@penww

@penww penww commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

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.

  • 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.

Fixes #1222

image

No color:
image

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

@mergify

mergify Bot commented Jun 26, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

- 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>
@penww

penww commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Hi @skyegalaxy, do you have suggestions for this PR?

@penww

penww commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

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.

@kscottz

kscottz commented Jul 10, 2026

Copy link
Copy Markdown

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 skyegalaxy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm. had meant to review this a while ago so thank you for your patience!

@fujitatomoya fujitatomoya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@penww

penww commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

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)

image

That said, I do not want to be too strict about default-on behavior. If default-off, or an explicit --color/--no-color option or --color=auto|always|never, would be more acceptable for ros2cli, I am open to updating the PR in that direction.

Please let me know which default policy you would prefer, and I can adjust the PR accordingly.

@fujitatomoya

Copy link
Copy Markdown
Collaborator

If default-off, or an explicit --color/--no-color option or --color=auto|always|never, would be more acceptable for ros2cli, I am open to updating the PR in that direction.

i am still inclined to take this path, but let's hear more opinion here. thanks for being constructive, i really appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optional colorized output support

4 participants