Bug 28887 - colored prompt length not calculated correctly
Summary: colored prompt length not calculated correctly
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: tui (show other bugs)
Version: 11.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-13 16:58 UTC by seanga2
Modified: 2023-05-26 16:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description seanga2 2022-02-13 16:58:43 UTC
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.
Comment 1 Andreas Schwab 2022-02-13 17:47:19 UTC
You can use \1 and \2 to mark the start and end of invisible characters.  gdb should perhaps support the \[\] brackets like bash.
Comment 2 seanga2 2022-02-13 17:50:41 UTC
Thanks!

Is this documented anywhere?
Comment 3 Hannes Domani 2022-02-17 16:17:30 UTC
https://sourceware.org/gdb/onlinedocs/gdb/gdb_002eprompt.html says it supports \[\], but \1\2 are not listed there.
Comment 4 Andreas Schwab 2022-02-17 16:32:38 UTC
That works with the python interface, but not with set prompt.
Comment 5 Hannes Domani 2022-02-17 16:35:56 UTC
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
Comment 6 Andreas Schwab 2022-02-17 17:15:31 UTC
So far the theory.
Comment 7 Tom de Vries 2023-05-26 16:12:41 UTC
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.