Skip to content

Instantly share code, notes, and snippets.

@clementsjj
Last active January 10, 2020 16:23
Show Gist options
  • Save clementsjj/c0184c58df7661ff2ee3920b4bdad9bf to your computer and use it in GitHub Desktop.
Save clementsjj/c0184c58df7661ff2ee3920b4bdad9bf to your computer and use it in GitHub Desktop.
f = {'red':'31m',
'green':'32m',
'yellow':'33m',
'blue':'34m',
'magenta':'35m',
'cyan':'36m',
'lightgray':'37m',
'darkgray':'90m',
'white':'97m'}
def colorize(color, text):
colortext=f'\033[{color}{text}\033[00m'
return colortext
print(colorize(f['red'], 'Hello, World!')
# Hello, World! (In Red)
# Alternatively, a function wrapper for each specific color can easily be dropped into any project...
def red(text):
# Will print in Red
colortext = f'\033[31m{text}\033[00m'
return colortext
def blue(text):
# Will Print in Blue
colortext = f'\033[34m{text}\033[00m'
return colortext
def magenta(text):
colortext = f'\033[35m{text}\033[00m'
return colortext
def cyan(text):
colortext = f'\033[36m{text}\033[00m'
return colortext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment