Skip to content

Fix character-valued ANSI_SEQUENCES entries inserting their escape sequence - #2179

Open
draarivpatel-ui wants to merge 1 commit into
prompt-toolkit:mainfrom
draarivpatel-ui:fix/char-valued-ansi-sequences
Open

draarivpatel-ui wants to merge 1 commit into
prompt-toolkit:mainfrom
draarivpatel-ui:fix/char-valued-ansi-sequences

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Fixes #2086.

ANSI_SEQUENCES may map an escape sequence to a plain single character rather than a Keys member (for example, what a terminal in xterm modifyOtherKeys=2 mode sends for Shift+N). Such an entry resolved to the correct key, but the resulting KeyPress carried the raw escape sequence as its data payload, so the sequence itself was typed into the buffer:

ANSI_SEQUENCES["\x1b[27;2;78~"] = "N"
presses = []
p = Vt100Parser(presses.append)
p.feed("\x1b[27;2;78~"); p.flush()
presses[0].data  # was '\x1b[27;2;78~', now 'N'

The parser now substitutes the character itself as the data payload for plain-character mappings. Escape sequences mapping to Keys members are unchanged, and so are tuple-valued entries (used for meta/alt key combinations), where only the first key press carries the payload.

Verified end to end through a real PromptSession using the reproduction from the issue: input "ab" + "\x1b[27;2;78~" + "cd\r" now yields abNcd instead of embedding the raw escape sequence. Regression test added in tests/test_inputstream.py; the full test suite passes (157 passed), and ruff check, ruff format --check and mypy are clean on the changed files.

…quence

When an entry in ANSI_SEQUENCES maps to a plain character rather than a
Keys member, the key press carried the raw escape sequence as data, so
the sequence itself was typed into the buffer instead of the character.

Fixes prompt-toolkit#2086
Copilot AI balanced review requested due to automatic review settings November 25, 2026 22:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Character-valued ANSI_SEQUENCES entries insert their escape sequence instead of the character

2 participants