Created
April 1, 2020 18:01
-
-
Save Pr1meSuspec7/55ced5e104954dff339f23d5e24567e4 to your computer and use it in GitHub Desktop.
Simple colorize output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COLORS = {'grey': 30, 'red': 31, 'green': 32, 'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36, 'white': 37} | |
RESET = '\033[0m' | |
def colortext(text, color=None): | |
# Ex: print(colortext('some text', 'cyan')) | |
ascii_color = '\033[1;%dm%s' | |
if color is not None: | |
text = ascii_color % (COLORS[color], text) | |
text += RESET | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment