135 lines
3.3 KiB
Python
135 lines
3.3 KiB
Python
|
#!/usr/bin/python3
|
||
|
|
||
|
seven_row = [] # put the row of 7 in a list.
|
||
|
for number in range(15, 256, 6):
|
||
|
seven_row.append(number)
|
||
|
|
||
|
color_names = [
|
||
|
"black",
|
||
|
"orange",
|
||
|
"dark_green",
|
||
|
"dark_yellow",
|
||
|
"dark_blue",
|
||
|
"purple",
|
||
|
"dark_turquoise",
|
||
|
"light_gray",
|
||
|
"gray",
|
||
|
"red",
|
||
|
"green",
|
||
|
"yellow",
|
||
|
"blue",
|
||
|
"pink",
|
||
|
"turquoise",
|
||
|
"white"
|
||
|
]
|
||
|
color_ansi = {
|
||
|
"reset": "\033[0m",
|
||
|
"rs": "\033[0m",
|
||
|
"bold": "\033[1m",
|
||
|
"italic": "\033[3m",
|
||
|
"underline": "\033[4m",
|
||
|
"slow_blink": "\033[5m",
|
||
|
"rapid_blink": "\033[6m"
|
||
|
}
|
||
|
|
||
|
for color in range(0, 16):
|
||
|
color_ansi[color_names[color]] = f"\033[38;5;{color}m"
|
||
|
|
||
|
reset = color_ansi["reset"]
|
||
|
|
||
|
|
||
|
def get_text_colors(only_default: bool=False):
|
||
|
color_codes = []
|
||
|
for color in range(0, 16):
|
||
|
color_codes.append(f"\033[38;5;{color}m")
|
||
|
|
||
|
if only_default:
|
||
|
return color_codes
|
||
|
|
||
|
else:
|
||
|
for color in range(16, 256):
|
||
|
color_codes.append(f"\033[38;5;{color}m")
|
||
|
|
||
|
return color_codes
|
||
|
|
||
|
|
||
|
def get_background_colors(only_default: bool = False):
|
||
|
color_codes = []
|
||
|
for color in range(0, 16):
|
||
|
color_codes.append(f"\033[48;5;{color}m")
|
||
|
|
||
|
if only_default:
|
||
|
return color_codes
|
||
|
|
||
|
else:
|
||
|
for color in range(16, 256):
|
||
|
color_codes.append(f"\033[48;5;{color}m")
|
||
|
|
||
|
return color_codes
|
||
|
|
||
|
|
||
|
# Font effects
|
||
|
def print_font_effects():
|
||
|
print("Font effects")
|
||
|
print("reset: \\033[0m")
|
||
|
print(color_ansi["bold"] + "Bold: \\033[1m" + reset)
|
||
|
print(color_ansi["italic"] + "Italic: \\033[3m" + reset)
|
||
|
print(color_ansi["underline"] + "Underline: \\033[4m" + reset)
|
||
|
print(color_ansi["slow_blink"] + "Slow blink: \\033[5m" + reset)
|
||
|
print(color_ansi["rapid_blink"] + "Rapid blink: \\033[6m" + reset)
|
||
|
|
||
|
|
||
|
# Text colors
|
||
|
def print_text_colors():
|
||
|
print("Text")
|
||
|
print("Linux, BSD, div. Unixe, Apple & Windows ANSII 16 Colors:")
|
||
|
color_codes = ""
|
||
|
for color in range(0, 16):
|
||
|
color_codes += f"\033[38;5;{color}m\\033[38;5;{color}m "
|
||
|
color_codes += " " * (1 - (len(str(color)) - 1))
|
||
|
if color == 7:
|
||
|
color_codes += f"{reset}\n"
|
||
|
|
||
|
print(color_codes, reset)
|
||
|
|
||
|
print("\nLinux, BSD, div. Unixe XTERM 256 Colors:")
|
||
|
color_codes = ""
|
||
|
for color in range(16, 256):
|
||
|
color_codes += f"\033[38;5;{color}m\\033[38;5;{color}m "
|
||
|
color_codes += " " * (2 - (len(str(color)) - 1))
|
||
|
if color in seven_row:
|
||
|
color_codes += f"{reset}\n"
|
||
|
|
||
|
print(color_codes, reset)
|
||
|
|
||
|
|
||
|
# Background
|
||
|
def print_background_colors():
|
||
|
print("Background")
|
||
|
print("Linux, BSD, div. Unixe, Apple & Windows ANSII 16 Colors:")
|
||
|
color_codes = ""
|
||
|
for color in range(0, 16):
|
||
|
color_codes += f"\033[48;5;{color}m\\033[48;5;{color}m "
|
||
|
color_codes += " " * (1 - (len(str(color)) - 1))
|
||
|
if color == 7:
|
||
|
color_codes += f"{reset}\n"
|
||
|
|
||
|
print(color_codes, reset)
|
||
|
|
||
|
print("\nLinux, BSD, div. Unixe XTERM 256 Colors:")
|
||
|
color_codes = ""
|
||
|
for color in range(16, 256):
|
||
|
color_codes += f"\033[48;5;{color}m\\033[48;5;{color}m "
|
||
|
color_codes += " " * (2 - (len(str(color)) - 1))
|
||
|
if color in seven_row:
|
||
|
color_codes += f"{reset}\n"
|
||
|
|
||
|
print(color_codes, reset)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
print()
|
||
|
print_font_effects()
|
||
|
print()
|
||
|
print_text_colors()
|
||
|
print_background_colors()
|