Last active
August 29, 2015 13:56
-
-
Save bryjbrown/9139072 to your computer and use it in GitHub Desktop.
An example of using ANSI escape codes to colorize output for Python shell scripts.
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
def purple(string): | |
return '\033[95m' + string + '\033[0m' | |
def blue(string): | |
return '\033[94m' + string + '\033[0m' | |
def green(string): | |
return '\033[92m' + string + '\033[0m' | |
def yellow(string): | |
return '\033[93m' + string + '\033[0m' | |
def red(string): | |
return '\033[91m' + string + '\033[0m' | |
print purple("Barney said...") | |
print blue("I've got the blue text blues.") | |
print green("Good job, young grasshopper.") | |
print yellow("WARNING: You are about to do something stupid.") | |
print red("SNOWCRASH SNOWCRASH SNOWCRASH") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment