-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathall-termcolors.py
More file actions
executable file
·45 lines (35 loc) · 1.07 KB
/
Copy pathall-termcolors.py
File metadata and controls
executable file
·45 lines (35 loc) · 1.07 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
#!/usr/bin/env -S uv run
"""Output all termcolor colors
Shows all colors available in termcolor library, displaying both regular and dark variants.
"""
# /// script
# dependencies = [
# "termcolor",
# ]
# ///
from termcolor import COLORS, HIGHLIGHTS, colored
MAX_LEN = max(len(c) for c in HIGHLIGHTS)
def try_print(color):
try:
if color.startswith("on_"):
complement = 'black' if color.endswith('white') else 'white'
print(colored(color, color=complement, on_color=color), end="")
else:
print(colored(color, color), end="")
except KeyError:
print(end=' ' * len(color))
print(end=" " * (MAX_LEN - len(color)))
# Display colors with both regular and dark variants
for color in COLORS:
if "_" in color:
continue
# Special handling for black - show on white background
if color == "black":
print(colored("black", "black"), end=" ")
print(colored("<- (did you see Black)", "black", on_color="on_white"))
continue
try_print(color)
try_print(f"light_{color}")
try_print(f"on_{color}")
try_print(f"on_light_{color}")
print()