Fix interactive prompt: keep reverse-video escape inside readline non-printing markers - #900
Open
tkossak wants to merge 1 commit into
Open
Fix interactive prompt: keep reverse-video escape inside readline non-printing markers#900tkossak wants to merge 1 commit into
tkossak wants to merge 1 commit into
Conversation
…kers The colored prompt brackets its ANSI escapes with RL_PROMPT_START_IGNORE (\001) and RL_PROMPT_END_IGNORE (\002) so readline does not count them toward the prompt width. In the reverse-video opener, \002 was placed before the terminating 'm' of \x1b[7m, leaving 'm' outside the ignore region. readline counted it as a visible column, making the prompt one column wider than it renders. That off-by-one shifted readline's input-start position, so Backspace could not delete the first typed character. Move \002 to after the 'm' so the whole \x1b[7m sits inside the markers. This fixes both PROMPTMSG (reverse-video prompt) and the per-DB prompt suffix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In the interactive prompt, after typing characters and pressing Backspace repeatedly, the first typed character cannot be deleted (the cursor/redisplay is off by one column).
The colored prompt brackets its ANSI escapes with readline's non-printing markers
\001(RL_PROMPT_START_IGNORE) and\002(RL_PROMPT_END_IGNORE) so they aren't counted toward the prompt width. But in the reverse-video open sequence,\002is placed before the terminatingmof\x1b[7m, leaving themoutside the ignore region:The terminal still consumes
\x1b[7mas an invisible SGR toggle, but readline counts the leftovermas one visible column. So readline computes the prompt as 19 columns wide when it renders as 18 — an off-by-one that shifts readline's idea of where input begins, so Backspace stops one column early. The reset code\001\x1b[0m\002is already wrapped correctly, which is why the error is exactly one column.Fix — move
\002to after them, so the whole\x1b[7mis inside the markers:Two occurrences are affected:
PROMPTMSG(main reverse-video prompt) and the per-DB prompt suffix ([{bdb.dbname}]).Design notes
Purely a correction of the readline non-printing markers around the reverse-video SGR opener; no logic, API, or option changes. The closing
\x1b[0mwas already correctly bracketed and is left unchanged.Side effects
None expected. The change is inert when color is disabled (
--nc/NO_COLOR), since that path uses the plain, escape-freePROMPTMSG. Not OS-specific — it's a readline redisplay issue reproducible wherever GNU readline is used.Test cases
Minimal repro (no buku needed) — before the fix, type a word then Backspace to the start; the first char can't be removed:
Manual verification with buku:
Linting (per PR guidelines) — both clean on the change: