-
Notifications
You must be signed in to change notification settings - Fork 847
feat: allow exiting shell by pressing Ctrl-C 3 times #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,6 +187,8 @@ def __init__( | |
| self._current_prompt_approval_request: ApprovalRequest | None = None | ||
| self._approval_modal: ApprovalPromptDelegate | None = None | ||
| self._exit_after_run = False | ||
| self._consecutive_interrupts = 0 | ||
| self._last_interrupt_time = 0.0 | ||
| self._available_slash_commands: dict[str, SlashCommand[Any]] = { | ||
| **{cmd.name: cmd for cmd in soul.available_slash_commands}, | ||
| **{cmd.name: cmd for cmd in shell_slash_registry.list_commands()}, | ||
|
|
@@ -489,7 +491,21 @@ def _can_auto_trigger_pending() -> bool: | |
| continue | ||
|
|
||
| if event.kind == "interrupt": | ||
| console.print("[grey50]Tip: press Ctrl-D or send 'exit' to quit[/grey50]") | ||
| now = time.monotonic() | ||
| if now - self._last_interrupt_time < 2.0: | ||
| self._consecutive_interrupts += 1 | ||
| else: | ||
| self._consecutive_interrupts = 1 | ||
| self._last_interrupt_time = now | ||
|
Comment on lines
+495
to
+499
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This logic only checks elapsed time between interrupts and never clears the counter when normal prompt activity occurs, so Useful? React with 👍 / 👎. |
||
|
|
||
| remaining = 3 - self._consecutive_interrupts | ||
| if remaining <= 0: | ||
| console.print("Bye!") | ||
| break | ||
| console.print( | ||
| f"[grey50]Tip: press Ctrl-C {remaining} more time{'s' if remaining > 1 else ''} to quit," | ||
| " or press Ctrl-D, or send 'exit'[/grey50]" | ||
| ) | ||
| resume_prompt.set() | ||
| continue | ||
|
|
||
|
|
@@ -503,6 +519,7 @@ def _can_auto_trigger_pending() -> bool: | |
|
|
||
| user_input = event.user_input | ||
| assert user_input is not None | ||
| self._consecutive_interrupts = 0 | ||
| bg_auto_failures = 0 | ||
| deferred_bg_trigger = False | ||
| if not user_input: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.