@@ -324,6 +324,10 @@ class PromptSession(Generic[_T]):
324
324
:param input: `Input` object. (Note that the preferred way to change the
325
325
input/output is by creating an `AppSession`.)
326
326
:param output: `Output` object.
327
+ :param interrupt_exception: The exception type that will be raised when
328
+ there is a keyboard interrupt (control-c keypress).
329
+ :param eof_exception: The exception type that will be raised when there is
330
+ an end-of-file/exit event (control-d keypress).
327
331
"""
328
332
329
333
_fields = (
@@ -410,6 +414,8 @@ def __init__(
410
414
refresh_interval : float = 0 ,
411
415
input : Input | None = None ,
412
416
output : Output | None = None ,
417
+ interrupt_exception : type [BaseException ] = KeyboardInterrupt ,
418
+ eof_exception : type [BaseException ] = EOFError ,
413
419
) -> None :
414
420
history = history or InMemoryHistory ()
415
421
clipboard = clipboard or InMemoryClipboard ()
@@ -459,6 +465,8 @@ def __init__(
459
465
self .reserve_space_for_menu = reserve_space_for_menu
460
466
self .tempfile_suffix = tempfile_suffix
461
467
self .tempfile = tempfile
468
+ self .interrupt_exception = interrupt_exception
469
+ self .eof_exception = eof_exception
462
470
463
471
# Create buffers, layout and Application.
464
472
self .history = history
@@ -811,7 +819,7 @@ def _complete_like_readline(event: E) -> None:
811
819
@handle ("<sigint>" )
812
820
def _keyboard_interrupt (event : E ) -> None :
813
821
"Abort when Control-C has been pressed."
814
- event .app .exit (exception = KeyboardInterrupt , style = "class:aborting" )
822
+ event .app .exit (exception = self . interrupt_exception () , style = "class:aborting" )
815
823
816
824
@Condition
817
825
def ctrl_d_condition () -> bool :
@@ -826,7 +834,7 @@ def ctrl_d_condition() -> bool:
826
834
@handle ("c-d" , filter = ctrl_d_condition & default_focused )
827
835
def _eof (event : E ) -> None :
828
836
"Exit when Control-D has been pressed."
829
- event .app .exit (exception = EOFError , style = "class:exiting" )
837
+ event .app .exit (exception = self . eof_exception () , style = "class:exiting" )
830
838
831
839
suspend_supported = Condition (suspend_to_background_supported )
832
840
0 commit comments