Skip to content

Commit 58e14f4

Browse files
cleanup.
1 parent c6b7b44 commit 58e14f4

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

examples/input_selection/default.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
3+
from prompt_toolkit.formatted_text import HTML
4+
from prompt_toolkit.shortcuts import select_input
5+
6+
7+
def main() -> None:
8+
result = select_input(
9+
message=HTML("<u>Please select a dish</u>:"),
10+
options=[
11+
("pizza", "Pizza with mushrooms"),
12+
("salad", "Salad with tomatoes"),
13+
("sushi", "Sushi"),
14+
],
15+
default="salad",
16+
)
17+
print(result)
18+
19+
20+
if __name__ == "__main__":
21+
main()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
3+
from prompt_toolkit.formatted_text import HTML
4+
from prompt_toolkit.shortcuts import select_input
5+
6+
7+
def main() -> None:
8+
result = select_input(
9+
message=HTML("<u>Please select a dish</u>:"),
10+
options=[
11+
("pizza", "Pizza with mushrooms"),
12+
("salad", "Salad with tomatoes"),
13+
("sushi", "Sushi"),
14+
],
15+
mouse_support=True,
16+
)
17+
print(result)
18+
19+
20+
if __name__ == "__main__":
21+
main()

examples/input_selection/with-frame.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def main() -> None:
2222
("sushi", "Sushi"),
2323
],
2424
style=style,
25+
# Use `~is_done`, if you only want to show the frame while editing and
26+
# hide it when the input is accepted.
27+
# Use `True`, if you always want to show the frame.
2528
show_frame=~is_done,
2629
)
2730
print(result)

src/prompt_toolkit/shortcuts/input_selection.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,37 @@ def create_default_input_selection_style() -> BaseStyle:
3131

3232

3333
class InputSelection(Generic[_T]):
34+
"""
35+
Input selection prompt. Ask the user to choose among a set of options.
36+
37+
Example usage::
38+
39+
input_selection = InputSelection(
40+
message="Please select a dish:",
41+
options=[
42+
("pizza", "Pizza with mushrooms"),
43+
("salad", "Salad with tomatoes"),
44+
("sushi", "Sushi"),
45+
],
46+
default="pizza",
47+
)
48+
result = input_selection.prompt()
49+
50+
:param message: Plain text or formatted text to be shown before the options.
51+
:param options: Sequence of `(value, label)` tuples.
52+
:param default: Default value. If none is given, the first option is
53+
considered the default.
54+
:param mouse_support: Enable mouse support.
55+
:param style: :class:`.Style` instance for the color scheme.
56+
"""
57+
3458
def __init__(
3559
self,
3660
*,
3761
message: AnyFormattedText,
3862
options: Sequence[tuple[_T, AnyFormattedText]],
3963
default: _T | None = None,
40-
mouse_support: bool = True,
64+
mouse_support: bool = False,
4165
style: BaseStyle | None = None,
4266
symbol: str = ">",
4367
show_frame: FilterOrBool = False,
@@ -156,14 +180,37 @@ def select_input(
156180
message: AnyFormattedText,
157181
options: Sequence[tuple[_T, AnyFormattedText]],
158182
default: _T | None = None,
159-
mouse_support: bool = True,
183+
mouse_support: bool = False,
160184
style: BaseStyle | None = None,
161185
symbol: str = ">",
162186
show_frame: bool = False,
163187
enable_suspend: FilterOrBool = False,
164188
enable_abort: FilterOrBool = True,
165189
interrupt_exception: type[BaseException] = KeyboardInterrupt,
166190
) -> _T:
191+
"""
192+
Input selection prompt. Ask the user to choose among a set of options.
193+
194+
Example usage::
195+
196+
result= select_input(
197+
message="Please select a dish:",
198+
options=[
199+
("pizza", "Pizza with mushrooms"),
200+
("salad", "Salad with tomatoes"),
201+
("sushi", "Sushi"),
202+
],
203+
default="pizza",
204+
)
205+
206+
:param message: Plain text or formatted text to be shown before the options.
207+
:param options: Sequence of `(value, label)` tuples.
208+
:param default: Default value. If none is given, the first option is
209+
considered the default.
210+
:param mouse_support: Enable mouse support.
211+
:param style: :class:`.Style` instance for the color scheme.
212+
"""
213+
167214
return InputSelection[_T](
168215
message=message,
169216
options=options,

0 commit comments

Comments
 (0)