ros2 / ros2/ros2cli

Add optional colorized output support

Open
#1,222 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
262
Forks
228
Avg merge
23h 15m
Merged PRs (30d)
12

Description

Description

This issue adds optional colorized terminal output to ros2cli. Colorization is off by default and can be enabled in two ways:

  • Set the environment variable ROS_COLORIZED_OUTPUT=1 (requires stdout to be a TTY)
  • Pass the --color flag on the command line (e.g. ros2 --color topic echo /chatter)
Image
Motivation

ros2cli output — especially from commands like ros2 topic echo, ros2 interface show, and ros2 param dump — is often dense, structured text (YAML, IDL, key-value pairs). Without color, it is difficult to quickly distinguish field names from values, ROS type strings from plain text, or section headers from content. Colorized output is a standard ergonomic feature in modern CLI tools and has been a recurring community request.

Design / Implementation Considerations

Modified: ros2cli/cli.py

  • Adds --color CLI argument
  • Activates ColoringStdout wrapping when color is enabled, selecting the appropriate colorizer for the active command/verb

New file: ros2cli/color.py

  • Introduces a Colorizer base class and an extensible registry keyed by (command, verb) pairs
  • DefaultColorizer applies generic ANSI heuristics (ROS paths, type strings, YAML keys) as a fallback for unregistered commands
  • ColoringStdout wraps sys.stdout and colorizes output line-by-line
  • Built-in colorizers registered for: ros2 (help), topic echo, topic hz, topic bw, topic info, param get, param dump, interface show, component list
  • Third-party packages can register custom colorizers via ros2cli.color.register(command, verb, colorizer)
Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading ros2cli/cli.py to trace argument handling and stdout setup, then review the proposed ros2cli/color.py interfaces and registered command/verb pairs. Verify that both ROS_COLORIZED_OUTPUT=1 and --color enable TTY-aware colorization, while default output remains unchanged across the listed commands.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.