Skip to content

Instantly share code, notes, and snippets.

@zaneGittins
Created May 10, 2019 17:37
Show Gist options
  • Save zaneGittins/4ec2e6f35776cb2593baed72affe0732 to your computer and use it in GitHub Desktop.
Save zaneGittins/4ec2e6f35776cb2593baed72affe0732 to your computer and use it in GitHub Desktop.
# colors
# Author: Zane Gittins
import sys
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
ORANGE = '\033[33m'
BLUE = '\033[34m'
PURPLE = '\033[35m'
CYAN = '\033[36m'
LIGHTGRAY = '\033[37m'
DARKGRAY = '\033[90m'
LIGHTRED = '\033[91m'
LIGHTGREEN = '\033[92m'
YELLOW = '\033[93m'
LIGHTBLUE = '\033[94m'
PINK = '\033[95m'
LIGHTCYAN = '\033[96m'
ENDC = '\033[0m'
def pick_color(color):
color = str(color).upper()
color_code = ""
if color == "BLACK":
color_code = BLACK
elif color == "RED":
color_code = RED
elif color == "GREEN":
color_code = GREEN
elif color == "ORANGE":
color_code = ORANGE
elif color == "BLUE":
color_code = BLUE
elif color == "PURPLE":
color_code = PURPLE
elif color == "CYAN":
color_code = CYAN
elif color == "LIGHTGRAY":
color_code = LIGHTGRAY
elif color == "DARKGRAY":
color_code = DARKGRAY
elif color == "LIGHTRED":
color_code = LIGHTRED
elif color == "LIGHTGREEN":
color_code = LIGHTGREEN
elif color == "YELLOW":
color_code = YELLOW
elif color == "LIGHTBLUE":
color_code = LIGHTBLUE
elif color == "PINK":
color_code = PINK
elif color == "LIGHTCYAN":
color_code = LIGHTCYAN
return color_code
def ctext(color,text):
color_code = pick_color(color)
if color_code != "":
cret = (color_code + str(text) + ENDC)
return cret
else:
return text
def cprint(color, text):
color_code = pick_color(color)
if color_code != "":
print(color_code + str(text) + ENDC)
else:
print(text)
def cwrite(color, text):
color_code = pick_color(color)
if color_code != "":
sys.stdout.write(color_code + str(text) + ENDC)
else:
sys.stdout.write(text)
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment