From 429b8eceb4e053f8783440396c18e30d41509712 Mon Sep 17 00:00:00 2001 From: nftpoetrist Date: Tue, 5 May 2026 00:45:01 +0300 Subject: [PATCH] fix(cli): guard c-S-c key binding with try/except to prevent startup crash (#19895) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cli.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cli.py b/cli.py index 96ecb8ecfd..2c5df6fbc4 100644 --- a/cli.py +++ b/cli.py @@ -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):