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)
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
Description
This issue adds optional colorized terminal output to
ros2cli. Colorization is off by default and can be enabled in two ways:ROS_COLORIZED_OUTPUT=1(requires stdout to be a TTY)--colorflag on the command line (e.g.ros2 --color topic echo /chatter)Motivation
ros2clioutput — especially from commands likeros2 topic echo,ros2 interface show, andros2 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--colorCLI argumentColoringStdoutwrapping when color is enabled, selecting the appropriate colorizer for the active command/verbNew file:
ros2cli/color.pyColorizerbase class and an extensible registry keyed by(command, verb)pairsDefaultColorizerapplies generic ANSI heuristics (ROS paths, type strings, YAML keys) as a fallback for unregistered commandsColoringStdoutwrapssys.stdoutand colorizes output line-by-lineros2(help),topic echo,topic hz,topic bw,topic info,param get,param dump,interface show,component listros2cli.color.register(command, verb, colorizer)Additional Information
No response