Skip to content

Commit c125f79

Browse files
Allow passing exception classes for KeyboardInterrupt and EOFError in PromptSession.
1 parent 98659af commit c125f79

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/prompt_toolkit/shortcuts/prompt.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ def __init__(
410410
refresh_interval: float = 0,
411411
input: Input | None = None,
412412
output: Output | None = None,
413+
interrupt_exception: type[BaseException] = KeyboardInterrupt,
414+
eof_exception: type[BaseException] = EOFError,
413415
) -> None:
414416
history = history or InMemoryHistory()
415417
clipboard = clipboard or InMemoryClipboard()
@@ -459,6 +461,8 @@ def __init__(
459461
self.reserve_space_for_menu = reserve_space_for_menu
460462
self.tempfile_suffix = tempfile_suffix
461463
self.tempfile = tempfile
464+
self.interrupt_exception = interrupt_exception
465+
self.eof_exception = eof_exception
462466

463467
# Create buffers, layout and Application.
464468
self.history = history
@@ -811,7 +815,7 @@ def _complete_like_readline(event: E) -> None:
811815
@handle("<sigint>")
812816
def _keyboard_interrupt(event: E) -> None:
813817
"Abort when Control-C has been pressed."
814-
event.app.exit(exception=KeyboardInterrupt, style="class:aborting")
818+
event.app.exit(exception=self.interrupt_exception(), style="class:aborting")
815819

816820
@Condition
817821
def ctrl_d_condition() -> bool:
@@ -826,7 +830,7 @@ def ctrl_d_condition() -> bool:
826830
@handle("c-d", filter=ctrl_d_condition & default_focused)
827831
def _eof(event: E) -> None:
828832
"Exit when Control-D has been pressed."
829-
event.app.exit(exception=EOFError, style="class:exiting")
833+
event.app.exit(exception=self.eof_exception(), style="class:exiting")
830834

831835
suspend_supported = Condition(suspend_to_background_supported)
832836

0 commit comments

Comments
 (0)