-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample.py
More file actions
141 lines (109 loc) · 2.66 KB
/
example.py
File metadata and controls
141 lines (109 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# mypy: disable-error-code=assignment
from ItsPrompt.objects.prompts.separator import Separator
try:
from pandas import DataFrame
NO_PANDAS = False
except ModuleNotFoundError:
NO_PANDAS = True
from ItsPrompt.prompt import Prompt
# select
ans = Prompt.select(
'What food would you like?',
(Separator('The veggies'), 'Salad', Separator('The meaties'), 'Pizza', 'Burger'),
default='Pizza',
)
print(ans)
# raw_select
ans = Prompt.raw_select(
'What pizza would you like?',
('Salami', 'Hawaii', 'four-cheese'),
allow_keyboard=True,
)
print(ans)
# checkbox
ans = Prompt.checkbox(
'What beverages would you like?',
('Coke', 'Water', 'Juice'),
default_checked=('Water',),
disabled=("Coke",),
min_selections=1,
)
print(ans)
# expand
ans = Prompt.expand(
'Where do you want your food to be delivered?',
('my home', 'another home'),
allow_keyboard=True,
)
print(ans)
# standard input with simple lambda validation
ans = Prompt.input(
'Please type your id',
validate=lambda x: "test" in x,
)
print(ans)
# standard input with validation
def input_not_empty(input: str) -> str | None:
if len(input) == 0:
return 'Input field can not be empty!'
return None
ans = Prompt.input(
'Please type your name',
validate=input_not_empty,
)
print(ans)
# standard input with validation and completion
ans = Prompt.input(
'Please type your address',
validate=input_not_empty,
completions=['Mainstreet 4', 'Fifth way'],
completion_show_multicolumn=True,
)
print(ans)
# standard input with password (show_symbol)
ans = Prompt.input(
'Please type your password',
show_symbol='*',
)
print(ans)
# confirm
ans = Prompt.confirm(
'Is the information correct?',
default=True,
)
print(ans)
# table
if not NO_PANDAS:
data = DataFrame({
'Food': ['Pizza', 'Burger', 'Salad'],
'Qty': [1, 0, 0],
})
ans = Prompt.table(
'Please fill in your quantity',
data,
)
print(ans)
# styling
# examples for the different styling class components
Prompt.raw_select(question='question', options=(
'option',
'selected_option',
))
Prompt.input(
question='question',
default='grayout',
validate=lambda x: 'error',
)
# change default style
from ItsPrompt.data.style import default_style
default_style.error = 'fg:ansired bg:ansiwhite'
# create your own style
from ItsPrompt.data.style import PromptStyle
my_style = PromptStyle(
question_mark='fg:ansiblue',
error='fg:ansired bg:ansiwhite',
)
# copy default style
from ItsPrompt.data.style import create_from_default
my_style = create_from_default()
my_style.error = 'fg:ansired bg:ansiwhite'