|
| 1 | +nc = '\x1b[0m' |
| 2 | +hex = { |
| 3 | + 'br': '#ff0000', 'by': '#ffff00', 'bo': '#ffa500', 'bg': '#00ff00', |
| 4 | + 'bw': '#ffffff', 'dg': '#008000', 'gry': '#808080', 'blk': '#000000', 'tlBG': '#008080' |
| 5 | +} |
| 6 | + |
| 7 | +def hex_to_ansi(hex_color: str) -> str: |
| 8 | + r = int(hex_color[1:3], 16) |
| 9 | + g = int(hex_color[3:5], 16) |
| 10 | + b = int(hex_color[5:7], 16) |
| 11 | + return f'\x1b[38;2;{r};{g};{b}m' |
| 12 | + |
| 13 | +class _Schemes: |
| 14 | + @property |
| 15 | + def default(self) -> list[str]: |
| 16 | + return [hex_to_ansi(hex) for hex in [ |
| 17 | + '#00e5bc', '#18c8ae', '#30ac9f', '#488f91', '#607383', |
| 18 | + '#775674', '#8f3966', '#a71d57', '#bf0049', '#9a1b5e' |
| 19 | + ]] |
| 20 | + @property |
| 21 | + def rainbow(self) -> list[str]: |
| 22 | + return [hex_to_ansi(hex) for hex in [ |
| 23 | + '#e41a1c', '#ff7f00', '#ffff33', '#4daf4a', '#377eb8', |
| 24 | + '#984ea3', '#f781bf', '#999999', '#a65628', '#d95f02' |
| 25 | + ]] |
| 26 | +schemes = _Schemes() |
| 27 | + |
| 28 | +def __getattr__(hex_key: str) -> str: # add color.hex_key getters that return ANSI |
| 29 | + if hex_key in hex: return hex_to_ansi(hex[hex_key]) |
| 30 | + raise AttributeError(f"module 'color' has no attribute '{hex_key}'") |
0 commit comments