11
11
to_filter ,
12
12
)
13
13
from 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
+ )
15
20
from prompt_toolkit .key_binding .key_processor import KeyPressEvent
16
21
from prompt_toolkit .layout import (
17
22
AnyContainer ,
@@ -96,6 +101,7 @@ def __init__(
96
101
enable_suspend : FilterOrBool = False ,
97
102
enable_interrupt : FilterOrBool = True ,
98
103
interrupt_exception : type [BaseException ] = KeyboardInterrupt ,
104
+ key_bindings : KeyBindingsBase | None = None ,
99
105
) -> None :
100
106
if style is None :
101
107
style = create_default_choice_input_style ()
@@ -111,6 +117,7 @@ def __init__(
111
117
self .interrupt_exception = interrupt_exception
112
118
self .enable_interrupt = enable_interrupt
113
119
self .bottom_toolbar = bottom_toolbar
120
+ self .key_bindings = key_bindings
114
121
115
122
def _create_application (self ) -> Application [_T ]:
116
123
radio_list = RadioList (
@@ -225,7 +232,9 @@ def _suspend(event: E) -> None:
225
232
layout = layout ,
226
233
full_screen = False ,
227
234
mouse_support = self .mouse_support ,
228
- key_bindings = kb ,
235
+ key_bindings = merge_key_bindings (
236
+ [kb , DynamicKeyBindings (lambda : self .key_bindings )]
237
+ ),
229
238
style = self .style ,
230
239
)
231
240
@@ -249,6 +258,7 @@ def choice(
249
258
enable_suspend : FilterOrBool = False ,
250
259
enable_interrupt : FilterOrBool = True ,
251
260
interrupt_exception : type [BaseException ] = KeyboardInterrupt ,
261
+ key_bindings : KeyBindingsBase | None = None ,
252
262
) -> _T :
253
263
"""
254
264
Choice selection prompt. Ask the user to choose among a set of options.
@@ -297,4 +307,5 @@ def choice(
297
307
enable_suspend = enable_suspend ,
298
308
enable_interrupt = enable_interrupt ,
299
309
interrupt_exception = interrupt_exception ,
310
+ key_bindings = key_bindings ,
300
311
).prompt ()
0 commit comments