Add Text ANSI colors class

This commit is contained in:
Clemens Schwaighofer
2025-07-09 08:54:29 +09:00
parent 19197c71ff
commit 717080a009
3 changed files with 109 additions and 2 deletions

View File

@@ -0,0 +1,84 @@
"""
Basic ANSI colors
Set colors with print(f"something {Colors.yellow}colorful{Colors.end})
bold + underline + color combinations are possible.
"""
class Colors:
"""
ANSI colors defined
"""
# General sets
bold = '\033[1m'
underline = '\033[4m'
end = '\033[0m'
reset = '\033[0m'
# Define ANSI color codes as class attributes
black = "\033[30m"
red = "\033[31m"
green = "\033[32m"
yellow = "\033[33m"
blue = "\033[34m"
magenta = "\033[35m"
cyan = "\033[36m"
white = "\033[37m"
# Define bold/bright versions of the colors
black_bold = "\033[1;30m"
red_bold = "\033[1;31m"
green_bold = "\033[1;32m"
yellow_bold = "\033[1;33m"
blue_bold = "\033[1;34m"
magenta_bold = "\033[1;35m"
cyan_bold = "\033[1;36m"
white_bold = "\033[1;37m"
# BRIGHT, alternative
black_bright = '\033[90m'
red_bright = '\033[91m'
green_bright = '\033[92m'
yellow_bright = '\033[93m'
blue_bright = '\033[94m'
magenta_bright = '\033[95m'
cyan_bright = '\033[96m'
white_bright = '\033[97m'
@staticmethod
def disable():
"""
No colors
"""
Colors.bold = ''
Colors.underline = ''
Colors.end = ''
Colors.reset = ''
# normal
Colors.black = ''
Colors.red = ''
Colors.green = ''
Colors.yellow = ''
Colors.blue = ''
Colors.magenta = ''
Colors.cyan = ''
Colors.white = ''
# bold/bright
Colors.black_bold = ''
Colors.red_bold = ''
Colors.green_bold = ''
Colors.yellow_bold = ''
Colors.blue_bold = ''
Colors.magenta_bold = ''
Colors.cyan_bold = ''
Colors.white_bold = ''
# bold/bright alt
Colors.black_bright = ''
Colors.red_bright = ''
Colors.green_bright = ''
Colors.yellow_bright = ''
Colors.blue_bright = ''
Colors.magenta_bright = ''
Colors.cyan_bright = ''
Colors.white_bright = ''
# __END__