fix(cli): ignore terminal focus reports (salvage #16780) - #34429
Merged
Merged
Conversation
Ghostty/macOS window or tab navigation (Cmd+Shift+[ / ], Alt+Tab, etc.) can deliver terminal focus reports (CSI I / CSI O) to the running TUI. prompt_toolkit does not map those sequences by default, so its parser falls back to literal key presses (ESC, [, I/O) and inserts `[I` / `[O` into the prompt buffer after the ESC byte is handled. Fix: register the two sequences as Keys.Ignore in ANSI_SEQUENCES at parser level, plus a no-op kb.add(Keys.Ignore) handler so the default self-insert path never inserts focus-report bytes. Salvage notes: original PR put the helper in cli.py. Salvaged into hermes_cli/pt_input_extras.py alongside install_shift_enter_alias / install_ctrl_enter_alias to match the established pattern for ANSI_SEQUENCES augmentation. setdefault → in-check so any prior user registration wins. Closes #16780
Required by CI author validation after salvaging PR #16780.
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
2 |
First entries
tests/cli/test_cli_terminal_shortcuts.py:9: [unresolved-import] unresolved-import: Cannot resolve imported module `prompt_toolkit.keys`
tests/cli/test_cli_terminal_shortcuts.py:8: [unresolved-import] unresolved-import: Cannot resolve imported module `prompt_toolkit.input.vt100_parser`
✅ Fixed issues: none
Unchanged: 4891 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
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.
Salvage of #16780 by @blackpilledsoftware-prog onto current main (PR branch was 3500+ commits behind).
Ghostty / macOS window or tab navigation (Cmd+Shift+[ / ], Alt+Tab) can deliver terminal focus reports (
CSI I/CSI O) to the running TUI. prompt_toolkit does not map those sequences by default, so its parser falls back to literal key presses (ESC,[,I/O) and inserts[I/[Ointo the prompt buffer after the ESC byte is handled.Fix
Register both sequences as
Keys.IgnoreinANSI_SEQUENCESat the VT100 parser level, plus a no-opkb.add(Keys.Ignore)handler so the default self-insert path never fires on the consumed bytes.This is parser-level — strictly cleaner than the post-hoc regex stripping in
_strip_leaked_terminal_responses_with_metabecause the bytes never reach the buffer.Salvage notes
The original PR placed the helper as a top-level function in
cli.py. Salvaged intohermes_cli/pt_input_extras.pyalongsideinstall_shift_enter_aliasandinstall_ctrl_enter_aliasto match the established pattern for ANSI_SEQUENCES augmentation (which post-dated this PR). Registration usesif seq not in ANSI_SEQUENCES(setdefault behavior) so any prior user or downstream registration wins.Test rehomed to import from
pt_input_extrasand gained one additional case that verifies idempotency of repeat installs.Files
hermes_cli/pt_input_extras.pyinstall_ignored_terminal_sequences()functioncli.pykb.add(Keys.Ignore)no-op handlertests/cli/test_cli_terminal_shortcuts.pyValidation
tests/cli/test_cli_terminal_shortcuts.pytests/cli/test_cli_init.pytests/cli/test_ctrl_enter_newline.pytests/cli/test_cli_terminal_response_sanitizer.pyAttribution
@blackpilledsoftware-prog's design intent (parser-level Keys.Ignore + no-op handler) preserved. Authorship retained on the substantive commit via explicit
--author=. AUTHOR_MAP entries added in follow-up commit.Closes #16780
Infographic