Skip to content

Commit 5fde041

Browse files
Follow-up: accept 'show_frame' in 'prompt_async()' and accept extra key bindings in 'choice'. (#2011)
1 parent 2b9cd93 commit 5fde041

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/prompt_toolkit/application/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ def _restore_sigint_from_ctypes() -> Generator[None, None, None]:
16031603
have_ctypes_signal = False
16041604
else:
16051605
# GraalPy has the functions, but they don't work
1606-
have_ctypes_signal = sys.implementation.name != 'graalpy'
1606+
have_ctypes_signal = sys.implementation.name != "graalpy"
16071607

16081608
if have_ctypes_signal:
16091609
# PyOS_sighandler_t PyOS_getsig(int i)

src/prompt_toolkit/shortcuts/choice_input.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
to_filter,
1212
)
1313
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+
)
1520
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
1621
from 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()

src/prompt_toolkit/shortcuts/prompt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ async def prompt_async(
11521152
enable_open_in_editor: FilterOrBool | None = None,
11531153
tempfile_suffix: str | Callable[[], str] | None = None,
11541154
tempfile: str | Callable[[], str] | None = None,
1155+
show_frame: FilterOrBool = False,
11551156
# Following arguments are specific to the current `prompt()` call.
11561157
default: str | Document = "",
11571158
accept_default: bool = False,
@@ -1233,6 +1234,8 @@ async def prompt_async(
12331234
self.tempfile_suffix = tempfile_suffix
12341235
if tempfile is not None:
12351236
self.tempfile = tempfile
1237+
if show_frame is not None:
1238+
self.show_frame = show_frame
12361239

12371240
self._add_pre_run_callables(pre_run, accept_default)
12381241
self.default_buffer.reset(

0 commit comments

Comments
 (0)