70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
# SGR color constants
|
|
# rene-d 2018, modified 2025 for background support
|
|
|
|
class Colours:
|
|
""" ANSI color codes """
|
|
|
|
# Foreground colours
|
|
BLACK = "\033[0;30m"
|
|
RED = "\033[0;31m"
|
|
GREEN = "\033[0;32m"
|
|
BROWN = "\033[0;33m"
|
|
BLUE = "\033[0;34m"
|
|
PURPLE = "\033[0;35m"
|
|
CYAN = "\033[0;36m"
|
|
LIGHT_GRAY = "\033[0;37m"
|
|
DARK_GRAY = "\033[1;30m"
|
|
LIGHT_RED = "\033[1;31m"
|
|
LIGHT_GREEN = "\033[1;32m"
|
|
YELLOW = "\033[1;33m"
|
|
LIGHT_BLUE = "\033[1;34m"
|
|
LIGHT_PURPLE = "\033[1;35m"
|
|
LIGHT_CYAN = "\033[1;36m"
|
|
LIGHT_WHITE = "\033[1;37m"
|
|
|
|
# Background colours
|
|
BG_BLACK = "\033[40m"
|
|
BG_RED = "\033[41m"
|
|
BG_GREEN = "\033[42m"
|
|
BG_YELLOW = "\033[43m"
|
|
BG_BLUE = "\033[44m"
|
|
BG_PURPLE = "\033[45m"
|
|
BG_CYAN = "\033[46m"
|
|
BG_LIGHT_GRAY = "\033[47m"
|
|
BG_DARK_GRAY = "\033[100m"
|
|
BG_LIGHT_RED = "\033[101m"
|
|
BG_LIGHT_GREEN = "\033[102m"
|
|
BG_LIGHT_YELLOW = "\033[103m"
|
|
BG_LIGHT_BLUE = "\033[104m"
|
|
BG_LIGHT_PURPLE = "\033[105m"
|
|
BG_LIGHT_CYAN = "\033[106m"
|
|
BG_WHITE = "\033[107m"
|
|
|
|
# Styles
|
|
BOLD = "\033[1m"
|
|
FAINT = "\033[2m"
|
|
ITALIC = "\033[3m"
|
|
UNDERLINE = "\033[4m"
|
|
BLINK = "\033[5m"
|
|
NEGATIVE = "\033[7m"
|
|
CROSSED = "\033[9m"
|
|
END = "\033[0m"
|
|
|
|
# Cancel codes if not in a TTY
|
|
import sys, platform, ctypes
|
|
if not sys.stdout.isatty():
|
|
for _ in dir():
|
|
if isinstance(_, str) and _[0] != "_":
|
|
locals()[_] = ""
|
|
else:
|
|
if platform.system() == "Windows":
|
|
kernel32 = ctypes.windll.kernel32
|
|
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
|
|
del kernel32
|
|
|
|
|
|
if __name__ == '__main__':
|
|
for i in dir(Colours):
|
|
if i[0:1] != "_" and i != "END":
|
|
print("{:>20} {}".format(i, getattr(Colours, i) + i + Colours.END))
|