-
Notifications
You must be signed in to change notification settings - Fork 37
/
c.py
150 lines (97 loc) · 4.16 KB
/
c.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
# ──────────────────────────────────────────────────────────────────────────────
from sys import argv, exit
# ──────────────────────────────────────────────────────────────────────────────
def makergb(a):
return tuple(int(a.lstrip('#')[i:i+2], 16) for i in (0, 2, 4))
def makex1b(a:tuple):
return f'\\x1b[38;2;{a[0]};{a[1]};{a[2]}m'
# ──────────────────────────────────────────────────────────────────────────────
def main():
try:
_a = argv[1]
try:
_b = argv[2]
except IndexError:
_b = 'fg'
if _b == 'fg':
if (len(_a) == 6, len(_a) == 7):
print('\n' +\
makex1b(
makergb(_a)
)
+ '\n')
elif len(_a.split()) == 3:
print('\n' +\
makex1b(
tuple(
_a.replace('(', '').replace(')', '').replace(',', '')
)
)
+ '\n')
elif _b == 'bg':
if (len(_a) == 6, len(_a) == 7):
print('\n' +\
makex1b(
makergb(_a)
).replace('3', '4', 1)
+ '\n')
elif len(_a.split()) == 3:
print('\n' +\
makex1b(
tuple(
_a.replace('(', '').replace(')', '').replace(',', '')
).replace('3', '4', 1)
)
+ '\n')
except IndexError:
while True:
_a = input('\x1b[33m\n input the color code\n\n\x1b[34m ❯ \x1b[m')
if _a:
break
else:
print('\n\x1b[31m ! Error, please input at least the color code\n (RGB/HEX)(examples: #ffffff [hex] 255 255 255 [rgb])')
continue
_b = input('\x1b[33m\n Foreground or background?[FG/bg]\n\n\x1b[34m ❯ \x1b[m')
if not _b:
_b = 'fg'
if _b == 'fg':
if len(_a) == 6 or len(_a) == 7:
print('\n' +\
makex1b(
makergb(_a)
)
+ '\n')
elif len(_a.split()) == 3:
print('\n' +\
makex1b(
tuple(
_a.replace('(', '').replace(')', '').replace(',', '')
)
)
+ '\n')
else:
print('\nError\n')
exit(1)
elif _b == 'bg':
if len(_a) == 6 or len(_a) == 7:
print('\n' +\
makex1b(
makergb(_a)
).replace('3', '4', 1)
+ '\n')
elif len(_a.split()) == 3:
print('\n' +\
makex1b(
tuple(
_a.replace('(', '').replace(')', '').replace(',', '')
)
).replace('3', '4', 1)
+ '\n')
else:
print('\nError\n')
exit(1)
# ──────────────────────────────────────────────────────────────────────────────
try:
main()
except KeyboardInterrupt:
exit(130)