-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstopwatch.py
More file actions
59 lines (44 loc) · 1.26 KB
/
Copy pathstopwatch.py
File metadata and controls
59 lines (44 loc) · 1.26 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
import time
from datetime import datetime, timedelta
import key_stroke
import sevseg
from colterm import term
def print_time(current: datetime, is_on_hold: bool) -> None:
hour, minute, second = current.hour, current.minute, current.second
term.clear()
term.fg('white')
print(' * * * S T O P W A T C H * * *')
term.fg('cyan')
term.hide_cursor()
print(sevseg.hms_time_display(hour, minute, second))
term.fg('yellow')
print(' P A U S E D' if is_on_hold else '')
print(' Press Ctrl+C or Q to stop.')
print('Space bar toggles pause/continue.')
term.show_cursor()
term.fg('reset')
def main() -> None:
kb = key_stroke.KeyStroke()
current = datetime.min
is_on_hold = False
while True:
print_time(current, is_on_hold)
key = 'none'
if kb.kbhit():
key = kb.getch()
if key in {'q', 'Q'}:
break
if key == ' ':
is_on_hold = not is_on_hold
continue
if key != 'none':
continue
try:
time.sleep(1)
except KeyboardInterrupt:
break
if not is_on_hold:
current += timedelta(seconds=1)
print('\nBye!\n')
if __name__ == '__main__':
main()