-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathcli-clock.py
More file actions
executable file
·148 lines (121 loc) · 4.38 KB
/
cli-clock.py
File metadata and controls
executable file
·148 lines (121 loc) · 4.38 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
142
143
144
145
146
147
#!/usr/bin/env python
from re import sub
import sys
import signal
from time import sleep
from datetime import datetime
import os
CLOCK_STYLE = 24
DIGIT_COLOR = "CYAN"
VOID_COLOR = "BLACK"
LETTER_COLOR = "YELLOW"
PUNCT_COLOR = "YELLOW"
PAD_WIDTH = 0
strings = {
"0" : "######|##__##|##--##|##__##|######",
"1" : "----##|--__##|----##|--__##|----##",
"2" : "######|--__##|######|##__--|######",
"3" : "######|--__##|######|--__##|######",
"4" : "##--##|##__##|######|--__##|----##",
"5" : "######|##__--|######|--__##|######",
"6" : "######|##__--|######|##__##|######",
"7" : "######|--__##|----##|--__##|----##",
"8" : "######|##__##|######|##__##|######",
"9" : "######|##__##|######|--__##|----##",
"A" : "_AAAA_|AA__AA|AAAAAA|AA__AA|AA__AA",
"B" : "AAAAA_|AA__AA|AAAAA_|AA__AA|AAAAAA",
"C" : "_AAAA_|AA__AA|AA____|AA__AA|_AAAA_",
"D" : "AAAAA_|AA__AA|AA__AA|AA__AA|AAAAA_",
"E" : "AAAAAA|AA____|AAAAAA|AA____|AAAAAA",
"F" : "AAAAAA|AA____|AAAA__|AA____|AA____",
"G" : "_AAAA_|AA____|AA_AAA|AA__AA|_AAAA_",
"H" : "AA__AA|AA__AA|AAAAAA|AA__AA|AA__AA",
"I" : "AAAA|_AA_|_AA_|_AA_|AAAA",
"J" : "___AAA|____AA|____AA|AA__AA|_AAAA_",
"K" : "AA__AA|AA_AA_|AAAA__|AA_AA_|AA__AA",
"L" : "AA____|AA____|AA____|AA____|AAAAAA",
"M" : "AA___AA|AAA_AAA|AAAAAAA|AA_A_AA|AA___AA",
"N" : "AA__AA|AAA_AA|AAAAAA|AA_AAA|AA__AA",
"O" : "_AAAA_|AA__AA|AA__AA|AA__AA|_AAAA_",
"P" : "AAAAAA|AA__AA|AAAAAA|AA____|AA____",
"Q" : "_AAAA_|AA__AA|AA__AA|AA_AAA|_AAAA_",
"R" : "AAAAA_|AA__AA|AAAAAA|AA_AA_|AA__AA",
"S" : "_AAAAA|AA____|_AAAA_|____AA|AAAAA_",
"T" : "AAAAAA|__AA__|__AA__|__AA__|__AA__",
"U" : "AA__AA|AA__AA|AA__AA|AA__AA|_AAAA_",
"V" : "AA__AA|AA__AA|AA__AA|_AAAA_|__AA__",
"W" : "AA___AA|AA_A_AA|AAAAAAA|AAA_AAA|AA___AA",
"X" : "AA__AA|_AAAA_|__AA__|_AAAA_|AA__AA",
"Y" : "AA__AA|AA__AA|_AAAA_|__AA__|__AA__",
"Z" : "AAAAAA|___AA_|__AA__|_AA___|AAAAAA",
">" : "________|________|________|________|________",
":" : "__|::|__|::|__",
"," : "__|__|__|::|_:",
"!" : "::|::|::|__|::",
"." : "__|__|__|__|::",
";" : "__|::|__|::|_:",
" " : "__|__|__|__|__",
"~" : "------|--__--|------|--__--|------"
}
colors = {
"BLACK" : "0",
"RED" : "1",
"GREEN" : "2",
"YELLOW" : "3",
"BLUE" : "4",
"MAGENTA" : "5",
"CYAN" : "6",
"WHITE" : "7"
}
DC = "\033[3" + colors[DIGIT_COLOR] + ";4" + colors[DIGIT_COLOR] + "m"
#VC = "\033[9" + colors[VOID_COLOR] + ";10" + colors[VOID_COLOR] + "m"
VC = "\033[38;5;234m\033[48;5;234m"
LC = "\033[3" + colors[LETTER_COLOR] + ";4" + colors[LETTER_COLOR] + "m"
PC = "\033[3" + colors[PUNCT_COLOR] + ";4" + colors[PUNCT_COLOR] + "m"
NC = "\033[0m"
def clear():
os.system('cls' if os.name=='nt' else 'printf "\Ec"')
def exit(signal, frame):
print("\033[5B" + "\033[?25h", end=' ') # move cursor below clock and make it reappear
sys.exit(0)
def initializeStrings():
for name, string in strings.items():
width = str(string.find("|"))
string = sub("(#+)", DC + r"\1" + NC, string) # colorize #'s in digit strings
string = sub("(-+)", VC + r"\1" + NC, string) # colorize -'s (void areas) in digit strings
string = sub("(A+)", LC + r"\1" + NC, string) # colorize A's in letter strings
string = sub("(:+)", PC + r"\1" + NC, string) # colorize :'s in puctuation strings
string = sub("_", " ", string) # replace _'s with spaces
string = sub("\|", "\033[" + width + "D" + "\033[1B", string) + "\033[4A" # add cursor movement
strings[name] = string
import fcntl, termios, struct
def terminalSize():
h, w, hp, wp = struct.unpack('HHHH',
fcntl.ioctl(0, termios.TIOCGWINSZ,
struct.pack('HHHH', 0, 0, 0, 0)))
return w, h
def drawClock():
terminalSize_log = "0"
while True:
terminalSize_cur = terminalSize()
if terminalSize_cur != terminalSize_log:
terminalSize_log = terminalSize_cur
clear()
print("\033[0;0H" + "\033[?25l") # move cursor to 0,0 and hide it
if CLOCK_STYLE == 12:
string = datetime.now().strftime("%I:%M") # 12-hour clock
#string = datetime.now().strftime("%I:%M:%S") # 12-hour clock
if string[0] == "0":
string = "~" + string[1:]
if CLOCK_STYLE == 24:
string = datetime.now().strftime("%H:%M") # 24-hour clock
#string = datetime.now().strftime("%H:%M:%S") # 24-hour clock
print("", end=' ')
for i in list(string):
print(" " * PAD_WIDTH, end=' ')
sys.stdout.write(strings[i])
sys.stdout.flush()
sleep((1000000 - datetime.now().microsecond) / 1000000.0)
signal.signal(signal.SIGINT, exit)
initializeStrings()
drawClock()