1111 to_filter ,
1212)
1313from prompt_toolkit .formatted_text import AnyFormattedText
14- from prompt_toolkit .key_binding .key_bindings import KeyBindings
14+ from prompt_toolkit .key_binding .key_bindings import (
15+ DynamicKeyBindings ,
16+ KeyBindings ,
17+ KeyBindingsBase ,
18+ merge_key_bindings ,
19+ )
1520from prompt_toolkit .key_binding .key_processor import KeyPressEvent
1621from prompt_toolkit .layout import (
1722 AnyContainer ,
@@ -96,6 +101,7 @@ def __init__(
96101 enable_suspend : FilterOrBool = False ,
97102 enable_interrupt : FilterOrBool = True ,
98103 interrupt_exception : type [BaseException ] = KeyboardInterrupt ,
104+ key_bindings : KeyBindingsBase | None = None ,
99105 ) -> None :
100106 if style is None :
101107 style = create_default_choice_input_style ()
@@ -111,6 +117,7 @@ def __init__(
111117 self .interrupt_exception = interrupt_exception
112118 self .enable_interrupt = enable_interrupt
113119 self .bottom_toolbar = bottom_toolbar
120+ self .key_bindings = key_bindings
114121
115122 def _create_application (self ) -> Application [_T ]:
116123 radio_list = RadioList (
@@ -225,7 +232,9 @@ def _suspend(event: E) -> None:
225232 layout = layout ,
226233 full_screen = False ,
227234 mouse_support = self .mouse_support ,
228- key_bindings = kb ,
235+ key_bindings = merge_key_bindings (
236+ [kb , DynamicKeyBindings (lambda : self .key_bindings )]
237+ ),
229238 style = self .style ,
230239 )
231240
@@ -249,6 +258,7 @@ def choice(
249258 enable_suspend : FilterOrBool = False ,
250259 enable_interrupt : FilterOrBool = True ,
251260 interrupt_exception : type [BaseException ] = KeyboardInterrupt ,
261+ key_bindings : KeyBindingsBase | None = None ,
252262) -> _T :
253263 """
254264 Choice selection prompt. Ask the user to choose among a set of options.
@@ -297,4 +307,5 @@ def choice(
297307 enable_suspend = enable_suspend ,
298308 enable_interrupt = enable_interrupt ,
299309 interrupt_exception = interrupt_exception ,
310+ key_bindings = key_bindings ,
300311 ).prompt ()
0 commit comments