Skip to content

Commit 1debdbb

Browse files
Cleanup.
1 parent 8c2489b commit 1debdbb

File tree

5 files changed

+197
-2
lines changed

5 files changed

+197
-2
lines changed
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.input_selection 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/with-frame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ 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",
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()

0 commit comments

Comments
 (0)