Skip to content

Add optional colorized output support #1222

Open

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

Activity

  1. PrabodhGyawali commented on Jun 28, 2026

    @PrabodhGyawali

    Have you colorized Gazebo sim output as well, its just mess, e.g: if you have multiple nodes launched with a launch file?

  2. penww commented on Jul 8, 2026

    @penww
    ContributorAuthor

    Have you colorized Gazebo sim output as well, its just mess, e.g: if you have multiple nodes launched with a launch file?

    @PrabodhGyawali Thanks for your feedback😁. I think that case is related, but slightly different from the scope here.

    The Gazebo / multi-node launch output is mostly runtime process output managed by ros2 launch / launch, where stdout and stderr from multiple processes are interleaved. This issue is focused on colorizing structured ros2cli command output, such as ros2 node info, ros2 topic echo, ros2 interface show, and parameter output.

    I can try to add support for launch/launch_ros output later, but I would like to prioritize finishing the ros2cli command output colorization first.

  3. PrabodhGyawali commented on Jul 8, 2026

    @PrabodhGyawali

    No worries, thanks for the reply.

    I am currently using tmux scripts like this: https://gist.github.com/PrabodhGyawali/ff1444eb6042faefe5beabe3d6b0bb50 to launch multiple nodes for better control and visualization.

    OUT OF SCOPE Question:

    I have also noticed at times certain nodes may overdo logging, and would be cool as well if there was a way to control how many times certain things get logged, rather coding hacks for it each time, like rather than logging every 10 Hz it would do it every 500 Hz to make visualization of CLI output easier to read.

    Would appreciate any recommendations to efficiently deal with this.
    Thanks.

  4. penww commented on Jul 10, 2026

    @penww
    ContributorAuthor

    @PrabodhGyawali That's a good point. ROS nodes can already achieve this by using the RCLCPP_*_THROTTLE APIs (e.g., RCLCPP_INFO_THROTTLE) to limit log output frequency. However, that requires modifying the node source code, which is not always practical, especially for third-party nodes.

    It might be an interesting idea to provide this capability at the ros2 run / ros2 launch level, allowing users to throttle or filter log output without changing the application code.

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

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