Skip to content

The agent that grows with you

fix(cli): map Shift+symbol keys under modifyOtherKeys=2

SSepe368bff16523
diff --git a/hermes_cli/pt_input_extras.py b/hermes_cli/pt_input_extras.py
index 4b81e7f1878..6e113f9e3d3 100644
--- a/hermes_cli/pt_input_extras.py
+++ b/hermes_cli/pt_input_extras.py
@@ -241,6 +241,15 @@ def _modify_other_keys_aliases(ANSI_SEQUENCES: dict, Keys) -> dict[str, object]:
for modifier in (7, 8): # Ctrl+Alt and Ctrl+Alt+Shift — same normalization
_install_paired(modifier, {cp: (Keys.Escape, ctrl_key)})
+ # Shift+printable ASCII under modifyOtherKeys (tilde form):
+ # Under modifyOtherKeys=2, terminals (xterm, Ghostty) encode any modified key that produces
+ # a character (e.g. Shift+- -> '_', Shift+= -> '+', Shift+[ -> '{') as ESC[27;2;<produced_cp>~.
+ # Unlike Kitty CSI-u (which sends the unshifted key), the tilde-form codepoint is already the
+ # layout-resolved produced character, so mapping ESC[27;2;<cp>~ -> chr(cp) is layout-safe.
+ # Existing entries (e.g. Shift+Enter \x1b[27;2;13~, Shift+Tab) are preserved via setdefault.
+ for cp in range(33, 127):
+ _put(f"\x1b[27;2;{cp}~", chr(cp))
+
# The Esc KEY under Kitty disambiguate mode: ESC[27u (+ modifiers 1-16 incl. super 9+, and
# lock twins of the modifier-less form, which is how a lone Esc arrives with a lock on).
_put("\x1b[27u", Keys.Escape)
diff --git a/tests/hermes_cli/test_modify_other_keys_aliases.py b/tests/hermes_cli/test_modify_other_keys_aliases.py
index 5b04d1d7dc2..87dcac9b368 100644
--- a/tests/hermes_cli/test_modify_other_keys_aliases.py
+++ b/tests/hermes_cli/test_modify_other_keys_aliases.py
@@ -264,6 +264,55 @@ def test_modify_other_keys_shift_letter_produces_uppercase(letter):
)
+# ---------------------------------------------------------------------------
+# Shift+symbols (modifyOtherKeys tilde form)
+# ---------------------------------------------------------------------------
+
+ 33, # '!'
+ 34, # '"'
+ 35, # '#'
+ 36, # '$'
+ 43, # '+'
+ 58, # ':'
+ 60, # '<'
+ 62, # '>'
+ 63, # '?'
+ 64, # '@'
+ 95, # '_' (Shift+Minus)
+ 123, # '{'
+ 124, # '|'
+ 125, # '}'
+ 126, # '~'
+])
+def test_modify_other_keys_shift_symbol_produces_char(cp):
+ """Under modifyOtherKeys=2, Shift+symbol (e.g. Shift+- -> '_') emits
+ ESC[27;2;<produced_cp>~. It must parse to the produced character,
+ not leak literal escape text."""
+ ch = chr(cp)
+ mok_seq = f"\x1b[27;2;{cp}~"
+ assert _parse(mok_seq) == [ch], (
+ f"modifyOtherKeys Shift+symbol ({mok_seq!r}) should produce {ch!r}"
+ )
+
+
+def test_shift_symbol_data_normalized_in_buffer():
+ """End-to-end: Vt100Parser with install_keypress_data_normalization
+ must deliver the character in KeyPress.data, not the raw escape."""
+ from hermes_cli.pt_input_extras import install_keypress_data_normalization
+ install_keypress_data_normalization()
+
+ out = []
+ parser = Vt100Parser(out.append)
+ for c in "\x1b[27;2;95~":
+ parser.feed(c)
+ parser.flush()
+
+ assert len(out) == 1
+ assert out[0].key == "_"
+ assert out[0].data == "_"
+
+
def test_does_not_clobber_shift_enter_alias():
"""install_modify_other_keys_aliases must not overwrite mappings
installed by install_shift_enter_alias (modifier=2, not 5)."""