Skip to content

Add optional colorized output support #1222

@penww

Description

@penww

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions