-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcolortable
executable file
·74 lines (58 loc) · 1.81 KB
/
colortable
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
#!/usr/bin/env python3
#
# http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
#
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).
#
TEST_TEXT = ' gYw ' # sample text
PRINT_RAW = False
def test_colors(fg, bg, text=TEST_TEXT, raw=PRINT_RAW):
if raw:
escape = r'\033['
else:
escape = "\033["
if bg:
bg_mod = f"{escape}{bg}m"
else:
bg_mod = ''
return f"{escape}{fg}m{bg_mod}{text}{escape}m"
def print_table(fg_colors, bg_colors):
print()
print(' ' * 18 + ''.join(f"{str(x) + 'm':<8}" for x in bg_colors))
for fg in ['0'] + list(fg_colors):
for bold in ['', ';1']:
fgb = str(fg) + bold
print(" %5sm " % fgb, end='')
for bg in [None] + list(bg_colors):
print(test_colors(fg=fgb, bg=bg), end=' ')
print()
def print_palette():
if PRINT_RAW:
escape = r'\033['
else:
escape = "\033["
print()
i = 0
for row in [range(40, 48), range(100, 108)]:
for col in row:
print(f"{escape}{col}m {escape}m ", end='')
print()
for col in row:
print(f"{escape}{col}m xX {escape}m ", end='')
i += 1
print()
for col in row:
print(f"{escape}{col}m {escape}m ", end='')
print("\n")
print_table(range(30, 38), range(40, 48))
print_table(range(90, 98), range(100, 108))
print()
print_palette()
print()
print('The format for ANSI escapes is "\\033[" + <numbers> + "m"')
print('Multiple semicolon-separated directives may be included in <numbers>')