fix(cli): stop Shift+Space CSI bytes leaking into buffer (#88071) - #88097
fix(cli): stop Shift+Space CSI bytes leaking into buffer (#88071)#88097webtecnica wants to merge 1 commit into
Conversation
|
need to merge this |
|
This PR fixes more than Shift+Space: as of Bisect
$ git log --format='%h %s' 5d3c15aaa7..057dcdf236 -S'_EXTENDED_ENTER_KEYS_SEQ' -- cli.py
45f11263bd fix(tui): skip the kitty protocol push for Ghostty in the Ink TUI too
1a8fea3ce2 fix(cli): skip Kitty keyboard protocol push for Ghostty, use modifyOtherKeys only
$ git merge-base --is-ancestor 1a8fea3ce2 5d3c15aaa7; echo $?
1 # absent from the good build
$ git merge-base --is-ancestor 1a8fea3ce2 057dcdf236; echo $?
0 # present in the bad buildOne detail that makes this easy to misdate: author date is 2026-08-17, but it was committed to Why the bug was dormant until thenThe incomplete half of #87511 has been in the tree since 2026-08-16, but on Ghostty it was unreachable. While the kitty flag stack is active ( Two individually reasonable fixes composed into a regression: #87511 shipped an alias table that only half works, and the #87630 Ghostty workaround is what turned that path on. Mechanism (independently reproduced, matches this PR's analysis)>>> install_modify_other_keys_aliases()
>>> out = []; Vt100Parser(out.append).feed('\x1b[27;2;76~')
>>> [(kp.key, kp.data) for kp in out]
[('L', '\x1b[27;2;76~')]
Why CI stayed green through all of this
$ grep -c '\.data' tests/cli/test_modify_other_keys_aliases.py
0That is how #87511 shipped, and why the +127 lines this same file gained between 2026-08-19 and 2026-08-24 still didn't catch it. The 122 test lines in this PR are what closes that hole — arguably the more valuable half of the change. Scope noteThis PR normalises
It may also be worth reconsidering whether the push is right for Ghostty at all. Ghostty implements the kitty protocol natively, and anyone who already has Environment
CI here is green and the branch is |
|
have been seeing Shift + letter issue after recent update |
|
Confirming the fix works and adding scope data from a local port against macOS Terminal.app (not just Ghostty). Local verification (Hermes v0.20.5 / git 0268c0b, Python 3.11.15, prompt_toolkit 3.0.52, macOS 26.6.2): I ported this PR's 220 + 42 sibling tests all pass. Reproduction, root cause, and fix are exactly as you described in the PR — no surprises. One scope observation worth flagging to reviewers: the bisect blames commit So the fix in this PR is the right one and the merge would unblock a much wider blast radius than just Ghostty. +1 from me. Small local addition in case the maintainer wants it as a follow-up: I also added a |
What Changed
Adds
install_keypress_data_normalization()inhermes_cli/pt_input_extras.py, called from CLI startup alongside the other alias installers. It patchesVt100Parser._call_handlerso that when an extended-key sequence maps to a single plain character (Shift+Space →' ', Shift+letter → the uppercase letter, keypad digits/operators), theKeyPress.datafield carries the mapped character instead of the raw CSI bytes.The patch is idempotent (sentinel flag) and defensive (import failures degrade to a no-op), matching the existing
Vt100Parser.feedbracketed-paste patch pattern.Root Cause
Vt100Parser._call_handlerbuildsKeyPress(key, match.group(0))— the key was correctly remapped by the alias table (#86866 follow-up, #87511/#87630), but the data field still held the full raw prefix (e.g.\x1b[32;2u). prompt_toolkit's default character-insert binding (self-insert,basic.py) insertsevent.data, so the raw CSI bytes landed in the buffer:Shift+Space xterm→'ab\x1b[27;2;32~cd'Shift+Space kitty→'ab\x1b[32;2ucd'For a plain space both fields are
' ', which is why the bug was invisible there. The same leak class affected every string-valued alias: Shift+letter, keypad digits, keypad operators. The previous test only asserted onkey_press.key == ' '(parser output), so it passed while the buffer-level behavior leaked.Verification
KeyPress.dataequals the mapped character for Shift+Space (both xterm modifyOtherKeys and kitty CSI-u formats), Shift+letter, keypad digits, and that plain space typing is unchanged.Application+Buffer(the repro from the issue) and asserts the buffer contains'ab cd'with no raw CSI bytes.tests/cli/test_modify_other_keys_aliases.py: 178 passed.tests/cli/test_cli_shift_enter_newline.py,test_cli_cmd_backspace.py,test_cli_terminal_shortcuts.py: 20 passed.Closes #88071