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
This commit is contained in:
nftpoetrist 2026-05-05 00:45:01 +03:00 committed by GitHub
parent e493b1c482
commit 429b8eceb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

25
cli.py
View file

@ -10484,20 +10484,19 @@ class HermesCLI:
self._should_exit = True
event.app.exit()
@kb.add('c-S-c') # Ctrl+Shift+C
def handle_ctrl_shift_c(event):
"""Copy text to clipboard (terminal-native).
try:
@kb.add('c-S-c') # Ctrl+Shift+C — no-op, let terminal handle native copy
def handle_ctrl_shift_c(event):
"""No-op: let the terminal handle Ctrl+Shift+C natively.
This is a no-op at the application level. Terminal emulators
handle the actual copy operation when Ctrl+Shift+C is pressed.
This binding prevents Hermes from intercepting the keystroke
as an interrupt signal.
On macOS the standard copy shortcut is Cmd+C (no Hermes binding
needed). On Linux/Windows Ctrl+Shift+C is the conventional
terminal copy shortcut.
"""
return # No-op — let the terminal perform native copy
Wrapped in try/except because prompt_toolkit raises ValueError
("Invalid key: c-S-c") on platforms where this key spec is not
recognised. The binding is best-effort; if registration fails,
startup continues normally.
"""
return
except ValueError:
pass # prompt_toolkit on this platform/version doesn't support c-S-c
@kb.add('c-q') # Ctrl+Q
def handle_ctrl_q(event):