diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-17 08:18:57 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-17 08:18:57 +0000 |
commit | 13e7a0d1b7dc338648cc8cc39a37f8994d99feb2 (patch) | |
tree | bfef52b4542add4686880b57eb90661c811f3b51 /src/prompt_toolkit/shortcuts | |
parent | Adding debian version 3.0.46-1. (diff) | |
download | prompt-toolkit-13e7a0d1b7dc338648cc8cc39a37f8994d99feb2.tar.xz prompt-toolkit-13e7a0d1b7dc338648cc8cc39a37f8994d99feb2.zip |
Merging upstream version 3.0.47.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/prompt_toolkit/shortcuts')
-rw-r--r-- | src/prompt_toolkit/shortcuts/prompt.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/prompt_toolkit/shortcuts/prompt.py b/src/prompt_toolkit/shortcuts/prompt.py index 115d890..d0732bc 100644 --- a/src/prompt_toolkit/shortcuts/prompt.py +++ b/src/prompt_toolkit/shortcuts/prompt.py @@ -324,6 +324,10 @@ class PromptSession(Generic[_T]): :param input: `Input` object. (Note that the preferred way to change the input/output is by creating an `AppSession`.) :param output: `Output` object. + :param interrupt_exception: The exception type that will be raised when + there is a keyboard interrupt (control-c keypress). + :param eof_exception: The exception type that will be raised when there is + an end-of-file/exit event (control-d keypress). """ _fields = ( @@ -410,6 +414,8 @@ class PromptSession(Generic[_T]): refresh_interval: float = 0, input: Input | None = None, output: Output | None = None, + interrupt_exception: type[BaseException] = KeyboardInterrupt, + eof_exception: type[BaseException] = EOFError, ) -> None: history = history or InMemoryHistory() clipboard = clipboard or InMemoryClipboard() @@ -459,6 +465,8 @@ class PromptSession(Generic[_T]): self.reserve_space_for_menu = reserve_space_for_menu self.tempfile_suffix = tempfile_suffix self.tempfile = tempfile + self.interrupt_exception = interrupt_exception + self.eof_exception = eof_exception # Create buffers, layout and Application. self.history = history @@ -811,7 +819,7 @@ class PromptSession(Generic[_T]): @handle("<sigint>") def _keyboard_interrupt(event: E) -> None: "Abort when Control-C has been pressed." - event.app.exit(exception=KeyboardInterrupt, style="class:aborting") + event.app.exit(exception=self.interrupt_exception(), style="class:aborting") @Condition def ctrl_d_condition() -> bool: @@ -826,7 +834,7 @@ class PromptSession(Generic[_T]): @handle("c-d", filter=ctrl_d_condition & default_focused) def _eof(event: E) -> None: "Exit when Control-D has been pressed." - event.app.exit(exception=EOFError, style="class:exiting") + event.app.exit(exception=self.eof_exception(), style="class:exiting") suspend_supported = Condition(suspend_to_background_supported) |