You've already forked pretty-print
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
# pretty_print.py
|
|
|
|
BRAND_COLORS = {
|
|
"Core": {
|
|
"Charcoal": "#0B1F31",
|
|
"Tech Blue": "#0F375F",
|
|
"Collaborative Green": "#00915B",
|
|
"Creative Yellow": "#F7BD24",
|
|
"Clear White": "#FDFDFD",
|
|
},
|
|
"Neutrals": {
|
|
"Cement": "#3B4B5A",
|
|
"Cement-50": "#858F98",
|
|
"Cement-25": "#B5BBC1",
|
|
"Dust": "#E5E8EA",
|
|
},
|
|
"Blues": {
|
|
"Darkest Blue": "#0B2844",
|
|
"Darker Blue": "#0F375F",
|
|
"Mid Blue": "#1B63AB",
|
|
"Lighter Blue": "#4894E2",
|
|
"Lightest Blue": "#68BBEA",
|
|
},
|
|
"Greens": {
|
|
"Darkest Green": "#06F72E",
|
|
"Darker Green": "#0B7952",
|
|
"Mid Green": "#00915B",
|
|
},
|
|
"Accents": {
|
|
"Purple": "#C000FF",
|
|
"Red": "#EF2563",
|
|
"Gold": "#F5BD24",
|
|
"Green": "#00915B",
|
|
"Blue": "#0F375F",
|
|
"Lavender": "#F032F7",
|
|
"Peach": "#F4E4E9",
|
|
"Glow": "#EFE9DA",
|
|
"Mint": "#DDF2E9",
|
|
"Sky": "#E2EAF2",
|
|
}
|
|
}
|
|
|
|
# Flatten the color dictionary
|
|
COLOR_LOOKUP = {name: hex_code for group in BRAND_COLORS.values() for name, hex_code in group.items()}
|
|
|
|
def hex_to_rgb(hex_code):
|
|
hex_code = hex_code.lstrip('#')
|
|
return tuple(int(hex_code[i:i+2], 16) for i in (0, 2, 4))
|
|
|
|
def rgb_escape(r, g, b, is_background=False):
|
|
return f"\033[{48 if is_background else 38};2;{r};{g};{b}m"
|
|
|
|
def pprint_color(msg, fg_color="Clear White", bg_color="Charcoal", end="\n"):
|
|
fg = COLOR_LOOKUP.get(fg_color)
|
|
bg = COLOR_LOOKUP.get(bg_color)
|
|
fg_code = rgb_escape(*hex_to_rgb(fg)) if fg else ""
|
|
bg_code = rgb_escape(*hex_to_rgb(bg), is_background=True) if bg else ""
|
|
reset = "\033[0m"
|
|
print(f"{fg_code}{bg_code}{msg}{reset}", end=end)
|