fix(cli): Ctrl+C clears input buffer before exiting

Previously, pressing Ctrl+C while text was typed in the input prompt
would immediately exit Hermes. Now follows standard shell behavior:

- Text in buffer → Ctrl+C clears the line (like bash)
- Empty buffer → Ctrl+C exits

This means accidentally hitting Ctrl+C while composing a message just
clears the input instead of killing the session. A second Ctrl+C on
the empty prompt still exits as expected.
This commit is contained in:
teknium1
2026-03-04 22:01:13 -08:00
parent 9aa2999388
commit 078e2e4b19

9
cli.py
View File

@@ -2490,8 +2490,13 @@ class HermesCLI:
print("\n⚡ Interrupting agent... (press Ctrl+C again to force exit)")
self.agent.interrupt()
else:
self._should_exit = True
event.app.exit()
# If there's text in the input buffer, clear it (like bash).
# If the buffer is already empty, exit.
if event.app.current_buffer.text:
event.app.current_buffer.reset()
else:
self._should_exit = True
event.app.exit()
@kb.add('c-d')
def handle_ctrl_d(event):