Skip to content

fix(cli): key combos survive NumLock/CapsLock under kitty CSI-u (salvage #89676 + #90291) - #90561

Merged
kshitijk4poor merged 4 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/kitty-lock-bits
Aug 20, 2026
Merged

fix(cli): key combos survive NumLock/CapsLock under kitty CSI-u (salvage #89676 + #90291)#90561
kshitijk4poor merged 4 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/kitty-lock-bits

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Key combos no longer die (leak as literal text like [99;133u) when NumLock or CapsLock is on under the kitty keyboard protocol. Closes #88221, closes #89651.

kitty/ghostty OR lock-key state into the modifier parameter of every key event while a lock is on (CapsLock=+64, NumLock=+128, both=+192), so Ctrl+C arrives as ESC[99;133u instead of ESC[99;5u and plain Down as ESC[1;129B instead of ESC[B. None of those variants were in ANSI_SEQUENCES, so with a lock enabled every combo — and on keypads every plain nav key — broke.

Composite salvage of the two strongest PRs in the 4-PR cluster, with authorship preserved via cherry-pick:

Changes

  • hermes_cli/pt_input_extras.py:
    • shared _lock_variants() helper; both cherry-picks and all follow-up sites use it
    • install_shift_enter_alias / install_ctrl_enter_alias / install_cmd_backspace_alias: CSI-u spellings get lock twins (Shift+Enter with NumLock = ESC[13;130u previously fell through)
    • legacy nav lock twins now derived from the existing table for all modifiers 1–16 (not just plain/shift as in fix(cli): map NumLock/CapsLock modifier-bit variants under kitty protocol #90291), covering Ctrl/Alt/Cmd-modified arrows + F1–F4 (SS3 base fallback) under locks
    • unmodified CSI-u keys (Tab/Enter/Space/Backspace at modifier 1) + lock twins
    • kitty PUA functional keys (keypad, F13–F24, Ignore range) + lock twins — NumLock especially matters here since it gates the keypad itself
  • tests/cli/test_modify_other_keys_aliases.py: contributors' tests + 8 follow-up tests for the widened surface
  • contributors/emails/: mapping for @grahfmusic

Validation

Before After
Ctrl+C + NumLock (ESC[99;133u) literal text leak Keys.ControlC
plain Down + NumLock (ESC[1;129B) literal text leak Keys.Down
Shift+Enter + NumLock (ESC[13;130u) literal text leak newline
Cmd+Backspace + NumLock (ESC[127;137u) literal text leak kill-line
KP_0 + NumLock (ESC[57399;129u) literal text leak "0"
modifyOtherKeys tilde form no lock twins still no lock twins (negative-tested)
  • 213 passed in tests/cli/test_modify_other_keys_aliases.py, 216+2s across tests/cli/
  • Byte-stream E2E through a real Vt100Parser: 8-sequence locked stream parses with zero CSI leaks
  • Idempotency: second install pass registers 0 sequences
  • Behavior parity vs origin/main on 14 non-lock sequences: identical

Credit

@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 20, 2026 05:56
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists needs-decision Awaiting maintainer decision before any implementation labels Aug 20, 2026
@kshitijk4poor
kshitijk4poor disabled auto-merge August 20, 2026 06:00
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 20, 2026 06:19
auto-merge was automatically disabled August 20, 2026 06:23

Pull Request is not mergeable

liuhao1024 and others added 3 commits August 20, 2026 11:55
…Lock

kitty and ghostty OR the CapsLock (64) / NumLock (128) state into the
CSI-u modifier parameter. With NumLock on, Ctrl+C arrives as
ESC[99;133u (5 + 128) instead of ESC[99;5u; the alias table had no
entry for it, so every key combo leaked as literal text like
[127;133u (NousResearch#89651). Install every CSI-u alias with the lock-bit
variants (+64/+128/+192); the xterm modifyOtherKeys encoding never
carries lock bits, so the ESC[27;N;CP~ form is left untouched. The
Esc-key registration now covers modifier 1 as well (1+128=129 is a
lone Esc with NumLock on).
…ocol

With the kitty keyboard protocol push active (CSI >1u disambiguate), kitty
encodes lock-key state into the CSI modifier field of function keys: a
plain Down with NumLock on arrives as ESC[1;129B (NumLock), ESC[1;65B
(CapsLock), or ESC[1;193B (both) instead of the legacy ESC[B. Stock
prompt_toolkit maps none of these, so the parser fires Escape and
inserts the remainder as literal text in the input line.

03bf85d restored the kitty push and completed the extended-key alias
table but left these lock-bit variants unmapped, so kitty + NumLock
still leaks [1;129A/B for arrow/nav keys.

Map modifier 129/65/193 (plain) and 130/66/194 (+shift) for arrows,
Home/End, Insert/Delete/PageUp/PageDown, and CSI-u Enter/Tab/Backspace/
Space to their plain keys.
…s, and PUA functional keys

Follow-up to the salvaged NousResearch#89676 + NousResearch#90291 lock-bit fixes: extract a shared _lock_variants() helper and cover the sites both PRs missed - install_shift_enter_alias / install_ctrl_enter_alias / install_cmd_backspace_alias CSI-u spellings, legacy CSI-letter and CSI-tilde navigation twins derived from the existing table for ALL modifiers 1-16 (not just plain/shift), plain F1-F4 SS3 fallback, unmodified CSI-u keys (Tab/Enter/Space/Backspace), and kitty PUA functional keys (keypad, F13-F24, Ignore range) under lock bits. 8 new tests.
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 20, 2026 06:26
auto-merge was automatically disabled August 20, 2026 06:30

Pull Request is not mergeable

@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 20, 2026 06:33
auto-merge was automatically disabled August 20, 2026 06:37

Pull Request is not mergeable

… forms, _lock_twins idiom

Post-review cleanup on the salvage: update the three alias-installer docstrings to mention lock twins (and fix ctrl-enter's stale 'stock maps none of these' claim - stock maps the tilde form to plain ControlM, which the overwrite fixes); skip the never-emitted modifier-1 tilde forms in _install_paired; name the twins-only idiom as _lock_twins() and use it at the legacy-nav + PUA sites; route the Esc loop through _lock_variants; hoist the per-base table lookup out of the lock loop in the legacy-nav section.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Having NumLock enabled prevents key combos [Bug]: kitty + NumLock on: CLI inserts raw CSI-u codes ([127;129u) instead of acting on keys

4 participants