ros2 / ros2cli

ROS 2 command line interface tools
Apache License 2.0
182 stars 162 forks source link

Add interactive mode for message creation #753

Open Flova opened 2 years ago

Flova commented 2 years ago

As discussed in #742 this PR adds an interactive TUI to the ros2 topic pub command.

The cli is mostly kept as it is, only an additional -i or --interactive flag is added. This allows the old behavior for scripting etc. while enhancing the experience in a manual use case.

Added dependencies

Features

Other changes:

Closes #742

The implementation for the topic pub command serves as a proof of concept. We can expand it to services and actions if the details are ironed out.

Demo

asciicast

clalancette commented 2 years ago

When we are using the interactive mode, can we just ask the user to fill in the contents via editor?

Let me show you an example where it wouldn't be ideal.

Right now in Rolling, you can do this:

$ ros2 topic pub /foo nav_msgs/msg/Path '{header: {stamp: {sec: 25, nanosec: 30}}}'

And you'lll get this output:

publisher: beginning loop
publishing #1: nav_msgs.msg.Path(header=std_msgs.msg.Header(stamp=builtin_interfaces.msg.Time(sec=25, nanosec=30), frame_id=''), poses=[])

publishing #2: nav_msgs.msg.Path(header=std_msgs.msg.Header(stamp=builtin_interfaces.msg.Time(sec=25, nanosec=30), frame_id=''), poses=[])

(that's the same as in Foxy, Galactic, and Humble).

But in Rolling, you can also do this:

$ ros2 topic pub /foo nav_msgs/msg/Path '{header: {stamp: now}}'

Which will get you this:

publisher: beginning loop
publishing #1: nav_msgs.msg.Path(header=std_msgs.msg.Header(stamp=builtin_interfaces.msg.Time(sec=1666012466, nanosec=830824864), frame_id=''), poses=[])

publishing #2: nav_msgs.msg.Path(header=std_msgs.msg.Header(stamp=builtin_interfaces.msg.Time(sec=1666012467, nanosec=831668171), frame_id=''), poses=[])

(notice that the time is increasing on every publish).

If we only allow interactive mode to specify numbers for the timestamps, then we can get the previous behavior, but not the new one. It would be much nicer if this was integrated together so that it would work for users like they expect.