-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
157 lines (121 loc) · 4.1 KB
/
demo.py
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import time
import colorlabels as cl
def welcome():
cl.section('ColorLabels Demo')
cl.newline()
cl.item('1. Overview of Labels')
cl.item('2. Progress Animations')
cl.item('3. Show Demo 1')
cl.item('4. Show Demo 2')
cl.item('5. Exit')
cl.newline()
def get_menu_option():
option = ''
while option not in {'1', '2', '3', '4', '5'}:
option = cl.input('Input your option: ').strip()
return int(option)
def overview():
cl.section('Overview of Labels')
cl.success('Good job! All test cases passed!')
cl.warning('Warning! Security update delayed!')
cl.error('Error! Failed to write file!')
cl.info('Server listening on port 8888.')
cl.progress('Downloading package, please wait...')
cl.plain('Nothing interesting.')
cl.question('A new version is present, would you like to update? (Y/N)')
def animations():
cl.section('Progress Animations')
cl.item('Static')
cl.progress('Downloading...')
time.sleep(3)
cl.item('Spin')
with cl.progress('Downloading...', mode=cl.PROGRESS_SPIN):
time.sleep(3)
cl.item('Expand')
with cl.progress('Downloading', mode=cl.PROGRESS_EXPAND):
time.sleep(6)
cl.item('Move')
with cl.progress('Downloading ', mode=cl.PROGRESS_MOVE):
time.sleep(4)
cl.item('Determinate')
with cl.progress('Downloading ', mode=cl.PROGRESS_DETERMINATE) as p:
time.sleep(1)
p.update(0.2, ' 20% (1MB/5MB) ETA 4s')
time.sleep(1)
p.update(0.4, ' 40% (2MB/5MB) ETA 3s')
time.sleep(1)
p.update(0.6, ' 60% (3MB/5MB) ETA 2s')
time.sleep(1)
p.update(0.8, ' 80% (4MB/5MB) ETA 1s')
time.sleep(1)
p.update(1, ' 100% (5MB/5MB)')
def demo1():
cl.section('Demo 1')
cl.info('Test program started.')
with cl.progress('Running test case 1...', cl.PROGRESS_SPIN, erase=True):
time.sleep(3)
cl.success('Test case 1: Passed')
with cl.progress('Running test case 2...', cl.PROGRESS_SPIN, erase=True):
time.sleep(3)
cl.success('Test case 2: Passed')
with cl.progress('Running test case 3...', cl.PROGRESS_SPIN, erase=True):
time.sleep(3)
cl.success('Test case 3: Passed')
with cl.progress('Running test case 4...', cl.PROGRESS_SPIN, erase=True):
time.sleep(3)
cl.error('Test case 4: Failed')
cl.info('Input: 1111')
cl.info('Expected output: 2222')
cl.info('Got: 3333')
cl.section('Test Result')
cl.info('3 out of 4 test cases passed.')
cl.info('Pass rate: 75%')
def demo2():
cl.section('Demo 2')
username = ''
while not username:
username = cl.input('Username: ').strip()
password = ''
while not password:
password = cl.password('Password: ')
cl.success('Successfully logged in.')
with cl.progress('Checking for update...', mode=cl.PROGRESS_SPIN):
time.sleep(3)
choice = ''
while choice.lower() not in {'y', 'n'}:
choice = cl.question('A new version is present, would you like to update? (Y/N)').strip()
if choice.lower() == 'y':
with cl.progress('Downloading ', mode=cl.PROGRESS_DETERMINATE) as p:
time.sleep(1)
p.update(0.2, ' 20% (1MB/5MB) ETA 4s')
time.sleep(2)
p.update(0.4, ' 40% (2MB/5MB) ETA 3s')
cl.error('Failed to download package. SSL handshake error.')
else:
cl.warning('Update delayed!')
def main():
try:
while True:
welcome()
option = get_menu_option()
if option != 5:
cl.newline()
if option == 1:
overview()
elif option == 2:
animations()
elif option == 3:
demo1()
elif option == 4:
demo2()
else:
cl.plain('Bye!')
break
cl.newline()
cl.input('Press Enter to continue...')
cl.newline()
except (KeyboardInterrupt, EOFError):
cl.newline()
cl.warning('Ctrl-C or EOF received, quitting.')
if __name__ == '__main__':
main()