Skip to content

Commit 8d0fb00

Browse files
Cleanup.
1 parent 8c2489b commit 8d0fb00

File tree

11 files changed

+218
-8
lines changed

11 files changed

+218
-8
lines changed

docs/pages/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Shortcuts
9696
:members: prompt, PromptSession, confirm, CompleteStyle,
9797
create_confirm_session, clear, clear_title, print_formatted_text,
9898
set_title, ProgressBar, input_dialog, message_dialog, progress_dialog,
99-
radiolist_dialog, yes_no_dialog, button_dialog
99+
radiolist_dialog, yes_no_dialog, button_dialog, select_input
100100

101101
.. automodule:: prompt_toolkit.shortcuts.progress_bar.formatters
102102
:members:

examples/input_selection/color.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from prompt_toolkit.formatted_text import HTML
4-
from prompt_toolkit.shortcuts.input_selection import select_input
4+
from prompt_toolkit.shortcuts import select_input
55
from prompt_toolkit.styles import Style
66

77

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from __future__ import annotations
2+
3+
from prompt_toolkit.formatted_text import HTML
4+
from prompt_toolkit.shortcuts import select_input
5+
from prompt_toolkit.styles import Style
6+
7+
8+
def main() -> None:
9+
style = Style.from_dict(
10+
{
11+
"selected-option": "bold",
12+
"frame.border": "#ff4444",
13+
"accepted frame.border": "#888888",
14+
}
15+
)
16+
17+
result = select_input(
18+
message=HTML("<u>Please select a dish</u>:"),
19+
options=[
20+
("pizza", "Pizza with mushrooms"),
21+
("salad", "Salad with tomatoes"),
22+
("sushi", "Sushi"),
23+
],
24+
style=style,
25+
show_frame=True,
26+
)
27+
print(result)
28+
29+
30+
if __name__ == "__main__":
31+
main()

examples/input_selection/many-options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from prompt_toolkit.shortcuts.input_selection import select_input
3+
from prompt_toolkit.shortcuts import select_input
44

55

66
def main() -> None:

examples/input_selection/simple-selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from prompt_toolkit.shortcuts.input_selection import select_input
3+
from prompt_toolkit.shortcuts import select_input
44

55

66
def main() -> None:

examples/input_selection/with-frame.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
from prompt_toolkit.filters import is_done
44
from prompt_toolkit.formatted_text import HTML
5-
from prompt_toolkit.shortcuts.input_selection import select_input
5+
from prompt_toolkit.shortcuts import select_input
66
from prompt_toolkit.styles import Style
77

88

99
def main() -> None:
1010
style = Style.from_dict(
1111
{
1212
"frame.border": "#884444",
13-
# Mark selected option in bold, when accepted:
14-
"accepted selected-option": "bold",
13+
"selected-option": "bold underline",
1514
}
1615
)
1716

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python
2+
"""
3+
Autocompletion example.
4+
5+
Press [Tab] to complete the current word.
6+
- The first Tab press fills in the common part of all completions
7+
and shows all the completions. (In the menu)
8+
- Any following tab press cycles through all the possible completions.
9+
"""
10+
11+
from prompt_toolkit import prompt
12+
from prompt_toolkit.completion import WordCompleter
13+
from prompt_toolkit.filters import is_done
14+
15+
animal_completer = WordCompleter(
16+
[
17+
"alligator",
18+
"ant",
19+
"ape",
20+
"bat",
21+
"bear",
22+
"beaver",
23+
"bee",
24+
"bison",
25+
"butterfly",
26+
"cat",
27+
"chicken",
28+
"crocodile",
29+
"dinosaur",
30+
"dog",
31+
"dolphin",
32+
"dove",
33+
"duck",
34+
"eagle",
35+
"elephant",
36+
"fish",
37+
"goat",
38+
"gorilla",
39+
"kangaroo",
40+
"leopard",
41+
"lion",
42+
"mouse",
43+
"rabbit",
44+
"rat",
45+
"snake",
46+
"spider",
47+
"turkey",
48+
"turtle",
49+
],
50+
ignore_case=True,
51+
)
52+
53+
54+
def main():
55+
text = prompt(
56+
"Give some animals: ",
57+
completer=animal_completer,
58+
complete_while_typing=False,
59+
# Only show the frame during editing. Hide when the input gets accepted.
60+
show_frame=~is_done,
61+
bottom_toolbar="Press [Tab] to complete the current word.",
62+
)
63+
print(f"You said: {text}")
64+
65+
66+
if __name__ == "__main__":
67+
main()
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python
2+
"""
3+
Autocompletion example.
4+
5+
Press [Tab] to complete the current word.
6+
- The first Tab press fills in the common part of all completions
7+
and shows all the completions. (In the menu)
8+
- Any following tab press cycles through all the possible completions.
9+
"""
10+
11+
from prompt_toolkit import prompt
12+
from prompt_toolkit.completion import WordCompleter
13+
from prompt_toolkit.styles import Style
14+
15+
animal_completer = WordCompleter(
16+
[
17+
"alligator",
18+
"ant",
19+
"ape",
20+
"bat",
21+
"bear",
22+
"beaver",
23+
"bee",
24+
"bison",
25+
"butterfly",
26+
"cat",
27+
"chicken",
28+
"crocodile",
29+
"dinosaur",
30+
"dog",
31+
"dolphin",
32+
"dove",
33+
"duck",
34+
"eagle",
35+
"elephant",
36+
"fish",
37+
"goat",
38+
"gorilla",
39+
"kangaroo",
40+
"leopard",
41+
"lion",
42+
"mouse",
43+
"rabbit",
44+
"rat",
45+
"snake",
46+
"spider",
47+
"turkey",
48+
"turtle",
49+
],
50+
ignore_case=True,
51+
)
52+
53+
54+
def main():
55+
style = Style.from_dict(
56+
{
57+
"frame.border": "#ff4444",
58+
"accepted frame.border": "#444444",
59+
}
60+
)
61+
text = prompt(
62+
"Give some animals: ",
63+
completer=animal_completer,
64+
complete_while_typing=False,
65+
show_frame=True,
66+
style=style,
67+
bottom_toolbar="Press [Tab] to complete the current word.",
68+
)
69+
print(f"You said: {text}")
70+
71+
72+
if __name__ == "__main__":
73+
main()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
"""
3+
Example of a colored prompt.
4+
"""
5+
6+
from prompt_toolkit import prompt
7+
from prompt_toolkit.styles import Style
8+
9+
style = Style.from_dict(
10+
{
11+
"frame.border": "#884444",
12+
}
13+
)
14+
15+
16+
def example():
17+
"""
18+
Style and list of (style, text) tuples.
19+
"""
20+
answer = prompt("Say something > ", style=style, show_frame=True)
21+
print(f"You said: {answer}")
22+
23+
24+
if __name__ == "__main__":
25+
example()

src/prompt_toolkit/shortcuts/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
radiolist_dialog,
1010
yes_no_dialog,
1111
)
12+
from .input_selection import select_input
1213
from .progress_bar import ProgressBar, ProgressBarCounter
1314
from .prompt import (
1415
CompleteStyle,
@@ -37,6 +38,8 @@
3738
# Progress bars.
3839
"ProgressBar",
3940
"ProgressBarCounter",
41+
# Input selection.
42+
"select_input",
4043
# Utils.
4144
"clear",
4245
"clear_title",

0 commit comments

Comments
 (0)