forked from awslabs/damo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_damo_ascii_color.py
49 lines (40 loc) · 1.41 KB
/
_damo_ascii_color.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
# SPDX-License-Identifier: GPL-2.0
# {name: [[background colors], [foreground colors]]}
colorsets = {
'gray':[
[232] * 10,
[237, 239, 241, 243, 245, 247, 249, 251, 253, 255]],
'flame':[
[232, 1, 1, 2, 3, 3, 20, 21,26, 27, 27],
[239, 235, 237, 239, 243, 245, 247, 249, 251, 255]],
'emotion':[
[232, 234, 20, 21, 26, 2, 3, 1, 1, 1],
[239, 235, 237, 239, 243, 245, 247, 249, 251, 255]],
}
def max_color_level():
return len(colorsets['gray'][0]) - 1
def color_mode_start_txt(colorset_name, level):
if not colorset_name in colorsets:
raise Exception('wrong colorset (%s)' % colorset)
colorset = colorsets[colorset_name]
bg = colorset[0][level]
fg = colorset[1][level]
return u'\u001b[48;5;%dm\u001b[38;5;%dm' % (bg, fg)
def color_mode_end_txt():
return u'\u001b[0m'
def colored(txt, colorset_name, level):
return ''.join([color_mode_start_txt(colorset_name, level), txt,
color_mode_end_txt()])
def color_samples(colorset_name):
samples = []
for level in range(max_color_level() + 1):
samples.append('%s%s' % (color_mode_start_txt(colorset_name, level),
'%d' % level))
samples.append(color_mode_end_txt())
return ''.join(samples)
def main():
for colorset_name in colorsets:
print('colorset_name')
print(color_samples(colorset_name))
if __name__ == '__main__':
main()