Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message template autocompletion broken #742

Open
Flova opened this issue Jul 29, 2022 · 6 comments · May be fixed by #753
Open

Message template autocompletion broken #742

Flova opened this issue Jul 29, 2022 · 6 comments · May be fixed by #753
Labels
help wanted Extra attention is needed

Comments

@Flova
Copy link

Flova commented Jul 29, 2022

When publishing a topic via ros2 topic pub or calling a service via ros2 service call the tab completion for the fields of the message is broken. The completion for the topic and message type works fine. The issue seems to be different between zsh and bash.

In zsh:
The field of the message are all handled are possible cli parameters that can be autocompleted pressing tab iterates through the fields. Each of the fields has its escaped indentation in the beginning and is individually selectable. Creating a valid message is impossible even for small msgs.
Example:

🐋 /home/florian/Projekt/bitbots/colcon_ws  ros2 topic pub /camera_info sensor_msgs/msg/CameraInfo -\ 0.0\
-\ 0.0\                        \ \ do_rectify:\ false\        --keep-alive                   p:\                            --qos-reliability              \ \ stamp:\                    width:\ 0\                   
-1                             \ \ frame_id:\ \'\'\           -n                             --print                        -r                             -t                             \ \ x_offset:\ 0\            
binning_x:\ 0\                 header:\                       \ \ \ \ nanosec:\ 0\           --qos-depth                    r:\                            --times                        \ \ y_offset:\ 0\            
binning_y:\ 0\                 \ \ height:\ 0\                --node-name                    --qos-durability               --rate                         -w                                                          
d:\ []\                        height:\ 0\                    --once                         --qos-history                  roi:\                          --wait-matching-subscriptions                               
distortion_model:\ \'\'\       k:\                            -p                             --qos-profile                  \ \ \ \ sec:\ 0\               \ \ width:\ 0\                                              

In bash:
Bash looks overall better as the message template is printed as one piece, but contains many escape characters.
Example:

[florian@flovat colcon_ws]$ ros2 topic pub /camera_info sensor_msgs/msg/CameraInfo 
-1
header:\^J\ \ stamp:\^J\ \ \ \ sec:\ 0\^J\ \ \ \ nanosec:\ 0\^J\ \ frame_id:\ \'\'\^Jheight:\ 0\^Jwidth:\ 0\^Jdistortion_model:\ \'\'\^Jd:\ []\^Jk:\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^Jr:\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^Jp:\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^J-\ 0.0\^Jbinning_x:\ 0\^Jbinning_y:\ 0\^Jroi:\^J\ \ x_offset:\ 0\^J\ \ y_offset:\ 0\^J\ \ height:\ 0\^J\ \ width:\ 0\^J\ \ do_rectify:\ false\
--keep-alive
-n
--node-name
--once
-p
--print
--qos-depth
--qos-durability
--qos-history
--qos-profile
--qos-reliability
-r
--rate
-t
--times
-w
--wait-matching-subscriptions
[florian@flovat colcon_ws]$ ros2 topic pub /camera_info sensor_msgs/msg/CameraInfo

I observed this behavior on all ros2 machines I have used so far, making the cli unusable for publishing topics.

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04 LTS
  • Installation type:
    • binaries
  • Version or commit hash:
    • 0.19.0-1jammy.20220711.162709
  • DDS implementation:
    • Cyclone & FastDDS

Steps to reproduce issue

  • source your terminal (zsh or bash)
  • type ros2 topic pub /camera_info sensor_msgs/msg/CameraInfo and press TAB

Expected behavior

A nicely formatted and editable string containing the message fields with their defaults should appear.

Actual behavior

Either the message is split and autocompleted in pieces (zsh) or cleaner (like in ros1) (bash)

Implementation considerations

I am not familiar with terminal formatting.

@Flova
Copy link
Author

Flova commented Jul 29, 2022

ROS 1 completion resulted in:

rostopic pub /cmd_vel geometry_msgs/Twist "linear:                 
  x: 0.0
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.0"

@clalancette
Copy link
Contributor

So this isn't ideal, but at least in bash if you start with a ", and then the first letter of the message, then autocompletion works as expected:

$ . /opt/ros/rolling/setup.bash 
$ ros2 topic pub /camera_info sensor_msgs/msg/CameraInfo "<TAB>
-1
header:^J  stamp:^J    sec: 0^J    nanosec: 0^J  frame_id: ''^Jheight: 0^Jwidth: 0^Jdistortion_model: ''^Jd: []^Jk:^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^Jr:^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^Jp:^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^J- 0.0^Jbinning_x: 0^Jbinning_y: 0^Jroi:^J  x_offset: 0^J  y_offset: 0^J  height: 0^J  width: 0^J  do_rectify: false
--keep-alive
-n
--node-name
--once
-p
--print
--qos-depth
--qos-durability
--qos-history
--qos-profile
--qos-reliability
-r
--rate
-t
--times
-w
--wait-matching-subscriptions
$ ros2 topic pub /camera_info sensor_msgs/msg/CameraInfo "h<TAB>
$ ros2 topic pub /camera_info sensor_msgs/msg/CameraInfo "header:
  stamp:
    sec: 0
    nanosec: 0
  frame_id: ''
height: 0
width: 0
distortion_model: ''
d: []
k:
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
r:
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
p:
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
binning_x: 0
binning_y: 0
roi:
  x_offset: 0
  y_offset: 0
  height: 0
  width: 0
  do_rectify: false"

It would be fantastic to figure out how to do that by default, so we don't need those beginning two letters.

@Flova
Copy link
Author

Flova commented Jul 29, 2022

We could also use something without newlines (maybe json), as this most likely breaks the autocomplete. It seems like most autocompletion systems don't play well with long multi line strings. Maybe the autocompletion could be dropped for this argument, and we add an "interactive mode" where the user is able to edit the msg after sending the command.

@Flova
Copy link
Author

Flova commented Jul 29, 2022

One could just leave the values field empy and a https://github.com/prompt-toolkit/python-prompt-toolkit multiline prompt is shown.

@Flova
Copy link
Author

Flova commented Jul 29, 2022

Editing the msg like this would be fancy, try the snipped:

from prompt_toolkit import prompt
from pygments.lexers.data import YamlLexer
from prompt_toolkit.lexers import PygmentsLexer

prompt("> ", multiline=True, default=
 """header:
   stamp:
     sec: 0
     nanosec: 0
   frame_id: ''
 height: 0
 width: 0
 distortion_model: ''
 d: []
 k:
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 r:
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 p:
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 - 0.0
 binning_x: 0
 binning_y: 0
 roi:
   x_offset: 0
   y_offset: 0
   height: 0
   width: 0
   do_rectify: false""", lexer=PygmentsLexer(YamlLexer))

Both deps are commonly used, in the Ubuntu repos and cross platform, but the syntax highlighting is not that nessesary if you want to keep the deps low.

asciicast

@clalancette
Copy link
Contributor

True. This even seems to work in Windows.

I'd be for adding a mode like this; I think it would be easier to use. I don't necessarily think we should make it the default (it is not useful for scripting), but for manual interaction it would be pretty cool.

@clalancette clalancette added the help wanted Extra attention is needed label Jul 29, 2022
@Flova Flova linked a pull request Sep 1, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants