1 | #!/usr/bin/python3
|
---|
2 |
|
---|
3 | from functools import partial
|
---|
4 |
|
---|
5 | def colors16():
|
---|
6 | for bold in [0, 1]:
|
---|
7 | for i in range(30, 38):
|
---|
8 | for j in range(40, 48):
|
---|
9 | print(f'\x1b[{bold};{i};{j}m {bold};{i};{j} |\x1b[0m', end='')
|
---|
10 | print()
|
---|
11 | print()
|
---|
12 |
|
---|
13 | for bold in [0, 1]:
|
---|
14 | for i in range(90, 98):
|
---|
15 | for j in range(100, 108):
|
---|
16 | print(f'\x1b[{bold};{i};{j}m {bold};{i};{j} |\x1b[0m', end='')
|
---|
17 | print()
|
---|
18 | print()
|
---|
19 |
|
---|
20 | def color1(c, n=0):
|
---|
21 | print(f'\x1b[{n};38;5;{c}m{c:4}\x1b[0m', end='')
|
---|
22 |
|
---|
23 | def color1_sep(c):
|
---|
24 | if (c - 15) % 18 == 0:
|
---|
25 | print()
|
---|
26 |
|
---|
27 | def color2(c):
|
---|
28 | print(f'\x1b[48;5;{c}m \x1b[0m', end='')
|
---|
29 |
|
---|
30 | def color2_sep(c):
|
---|
31 | if (c - 15) % 36 == 0:
|
---|
32 | print()
|
---|
33 | elif (c - 15) % 6 == 0:
|
---|
34 | print(' ', end='')
|
---|
35 |
|
---|
36 | def colors256(color, sepfunc):
|
---|
37 | for i in range(0, 8):
|
---|
38 | color(i)
|
---|
39 | print()
|
---|
40 | for i in range(8, 16):
|
---|
41 | color(i)
|
---|
42 | print('\n')
|
---|
43 |
|
---|
44 | for i in range(16, 232):
|
---|
45 | color(i)
|
---|
46 | sepfunc(i)
|
---|
47 | print()
|
---|
48 |
|
---|
49 | for i in range(232, 256):
|
---|
50 | color(i)
|
---|
51 | print('\n')
|
---|
52 |
|
---|
53 | def colors_gradient():
|
---|
54 | s= '/\\' * 40
|
---|
55 | for col in range(0, 77):
|
---|
56 | r = 255 - col * 255 // 76
|
---|
57 | g = col * 510 // 76
|
---|
58 | b = col * 255 // 76
|
---|
59 | if g > 255:
|
---|
60 | g = 510 - g
|
---|
61 | print(f'\x1b[48;2;{r};{g};{b}m\x1b[38;2;{255-r};{255-g};{255-b}m{s[col]}\x1b[0m', end='')
|
---|
62 | print()
|
---|
63 |
|
---|
64 | def other_attributes():
|
---|
65 | for i in range(0, 10):
|
---|
66 | print(f' \x1b[{i}mSGR {i:2}\x1b[m', end=' ')
|
---|
67 | print(' \x1b[53mSGR 53\x1b[m', end=' ') # overline
|
---|
68 | print('\n')
|
---|
69 | # https://askubuntu.com/a/985386/235132
|
---|
70 | for i in range(1, 6):
|
---|
71 | print(f' \x1b[4:{i}mSGR 4:{i}\x1b[m', end=' ')
|
---|
72 | print(' \x1b[21mSGR 21\x1b[m', end=' ')
|
---|
73 |
|
---|
74 | print(' \x1b[4:3m\x1b[58;2;135;0;255mtruecolor underline\x1b[59m\x1b[4:0m', end=' ')
|
---|
75 | print(' \x1b]8;;https://askubuntu.com/a/985386/235132\x1b\\hyperlink\x1b]8;;\x1b\\')
|
---|
76 |
|
---|
77 | if __name__ == '__main__':
|
---|
78 | print('basic 16 colors, foreground & background:\n')
|
---|
79 | colors16()
|
---|
80 |
|
---|
81 | print('256 colors:\n')
|
---|
82 | colors256(color1, color1_sep)
|
---|
83 |
|
---|
84 | print('256 colors, bold:\n')
|
---|
85 | colors256(partial(color1, n=1), color1_sep)
|
---|
86 |
|
---|
87 | print('256 colors, dim:\n')
|
---|
88 | colors256(partial(color1, n=2), color1_sep)
|
---|
89 |
|
---|
90 | print('256 colors, bold dim:\n')
|
---|
91 | colors256(partial(color1, n='1;2'), color1_sep)
|
---|
92 |
|
---|
93 | print('256 colors, solid background:\n')
|
---|
94 | colors256(color2, color2_sep)
|
---|
95 |
|
---|
96 | print('true colors gradient:\n')
|
---|
97 | colors_gradient()
|
---|
98 |
|
---|
99 | print('other attributes:\n')
|
---|
100 | other_attributes()
|
---|