Skip to content

Commit 429b8ec

Browse files
authored
fix(cli): guard c-S-c key binding with try/except to prevent startup crash (#19895)
PR #19884 added @kb.add('c-S-c') unconditionally. prompt_toolkit raises ValueError("Invalid key: c-S-c") during HermesCLI.__init__ on platforms where this key spec is not recognised — the process exits before reaching the prompt loop. Reported on macOS (#19894) and Linux (#19896) immediately after #19884 landed. Fix: wrap the registration in try/except ValueError so that startup continues cleanly on any platform/version that rejects the spec. Where the spec is accepted the binding is registered normally as a no-op, allowing the terminal to handle Ctrl+Shift+C natively as before. Fixes #19894 Fixes #19896
1 parent e493b1c commit 429b8ec

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

‎cli.py‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10484,20 +10484,19 @@ def handle_ctrl_c(event):
1048410484
self._should_exit = True
1048510485
event.app.exit()
1048610486

10487-
@kb.add('c-S-c') # Ctrl+Shift+C
10488-
def handle_ctrl_shift_c(event):
10489-
"""Copy text to clipboard (terminal-native).
10490-
10491-
This is a no-op at the application level. Terminal emulators
10492-
handle the actual copy operation when Ctrl+Shift+C is pressed.
10493-
This binding prevents Hermes from intercepting the keystroke
10494-
as an interrupt signal.
10495-
10496-
On macOS the standard copy shortcut is Cmd+C (no Hermes binding
10497-
needed). On Linux/Windows Ctrl+Shift+C is the conventional
10498-
terminal copy shortcut.
10499-
"""
10500-
return # No-op — let the terminal perform native copy
10487+
try:
10488+
@kb.add('c-S-c') # Ctrl+Shift+C — no-op, let terminal handle native copy
10489+
def handle_ctrl_shift_c(event):
10490+
"""No-op: let the terminal handle Ctrl+Shift+C natively.
10491+
10492+
Wrapped in try/except because prompt_toolkit raises ValueError
10493+
("Invalid key: c-S-c") on platforms where this key spec is not
10494+
recognised. The binding is best-effort; if registration fails,
10495+
startup continues normally.
10496+
"""
10497+
return
10498+
except ValueError:
10499+
pass # prompt_toolkit on this platform/version doesn't support c-S-c
1050110500

1050210501
@kb.add('c-q') # Ctrl+Q
1050310502
def handle_ctrl_q(event):

0 commit comments

Comments
 (0)