File tree Expand file tree Collapse file tree 5 files changed +197
-2
lines changed Expand file tree Collapse file tree 5 files changed +197
-2
lines changed Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments