Last active
August 29, 2015 13:57
-
-
Save KelSolaar/9446072 to your computer and use it in GitHub Desktop.
ANSI Colors
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
BACKGROUND_CODES = (("bBlack", "40m"), | |
("bRed", "41m"), | |
("bGreen", "42m"), | |
("bYellow", "43m"), | |
("bBlue", "44m"), | |
("bPurple", "45m"), | |
("bCyan", "46m"), | |
("bWhite", "47m"), | |
("bHighBlack", "100m"), | |
("bHighRed", "101m"), | |
("bHighGreen", "102m"), | |
("bHighYellow", "103m"), | |
("bHighBlue", "104m"), | |
("bHighPurple", "105m"), | |
("bHighCyan", "106m"), | |
("bHighWhite", "107m")) | |
FOREGROUND_CODES = (("black", "30m"), | |
("red", "31m"), | |
("green", "32m"), | |
("yellow", "33m"), | |
("blue", "34m"), | |
("purple", "35m"), | |
("cyan", "36m"), | |
("white", "37m"), | |
("boldBlack", "1;30m"), | |
("boldRed", "1;31m"), | |
("boldGreen", "1;32m"), | |
("boldYellow", "1;33m"), | |
("boldBlue", "1;34m"), | |
("boldPurple", "1;35m"), | |
("boldCyan", "1;36m"), | |
("boldWhite", "1;37m"), | |
("underlineBlack", "4;30m"), | |
("underlineRed", "4;31m"), | |
("underlineGreen", "4;32m"), | |
("underlineYellow", "4;33m"), | |
("underlineBlue", "4;34m"), | |
("underlinePurple", "4;35m"), | |
("underlineCyan", "4;36m"), | |
("underlineWhite", "4;37m"), | |
("highBlack", "0;90m"), | |
("highRed", "0;91m"), | |
("highGreen", "0;92m"), | |
("highYellow", "0;93m"), | |
("highBlue", "0;94m"), | |
("highPurple", "0;95m"), | |
("highCyan", "0;96m"), | |
("highWhite", "0;97m"), | |
("highBoldBlack", "1;90m"), | |
("highBoldRed", "1;91m"), | |
("highBoldGreen", "1;92m"), | |
("highBoldYellow", "1;93m"), | |
("highBoldBlue", "1;94m"), | |
("highBoldPurple", "1;95m"), | |
("highBoldCyan", "1;96m"), | |
("highBoldWhite", "1;97m")) | |
class AnsiColors(): | |
""" | |
Defines *ANSI* colors escape codes. | |
""" | |
reset = "\033[0m" | |
def _setAnsiColors(): | |
""" | |
Injects *ANSI* colors escape codes into :class:`AnsiColors` class. | |
""" | |
setColorAttribute = lambda x, y: setattr(AnsiColors, x, y) | |
for foregroundCodeName, foregroundCode in FOREGROUND_CODES: | |
setColorAttribute(foregroundCodeName, | |
"\033[{0}".format(foregroundCode)) | |
for backgroundCodeName, backgroundCode in BACKGROUND_CODES: | |
setColorAttribute(backgroundCodeName, | |
"\033[{0}".format(backgroundCode)) | |
for backgroundCodeName, backgroundCode in BACKGROUND_CODES: | |
for foregroundCodeName, foregroundCode in FOREGROUND_CODES: | |
setColorAttribute("{0}{1}".format(foregroundCodeName, | |
"{0}{1}".format(backgroundCodeName[0].upper(), backgroundCodeName[1:])), | |
"\033[{0}\033[{1}".format(foregroundCode, backgroundCode)) | |
_setAnsiColors() | |
import pprint | |
pprint.pprint(dir(AnsiColors)) | |
print AnsiColors.bRed | |
print AnsiColors.bHighCyan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment