When using gdb with a colored prompt such as set prompt \033[31mgdb$ \033[0m the length of the prompt will include the non-visible escape codes. This can be demonstrated by entering a long command: gdb$ some long command and then pressing UP and HOME (or C-P and C-A). The cursor will be placed on the space after "long," instead of on the s in "some", as expected. Additionally, if one presses DOWN (C-N), "some long" will remain at the beginning of the command. Despite this, the cursor is "logically" at the beginning of the command, which can be seen by editing the command and inspecting the history.
You can use \1 and \2 to mark the start and end of invisible characters. gdb should perhaps support the \[\] brackets like bash.
Thanks! Is this documented anywhere?
https://sourceware.org/gdb/onlinedocs/gdb/gdb_002eprompt.html says it supports \[\], but \1\2 are not listed there.
That works with the python interface, but not with set prompt.
The prompt docu [1] points to the python prompt docu for the list of acceptable escape sequences. [1] https://sourceware.org/gdb/onlinedocs/gdb/Prompt.html
So far the theory.
I've build gdb 11.1 (both with packaged readline (8.1) and system readline (7.0) in case this matters) and I can't reproduce this.