Skip to content

Instantly share code, notes, and snippets.

@lucansky
Last active November 6, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucansky/79f2a8f43e0a2fb8a806 to your computer and use it in GitHub Desktop.
Save lucansky/79f2a8f43e0a2fb8a806 to your computer and use it in GitHub Desktop.
Python 3 color printer
# Slick class for neat output coloring.
# Author: Adam Lucansky <xlucan01 at stud.fit.vutbr.cz>
# Created: 6th Nov 2015
# License: Public domain
class ColorPrint:
# List of terminal colors.
# Source: http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def __init__(self, text):
if type(text) == bytes:
text = text.decode('utf-8', 'backslashreplace')
self.text = text
def write(self, color, tag):
print(color + tag + self.text + ColorPrint.ENDC)
@staticmethod
def debug(text):
ColorPrint(text).write(ColorPrint.WARNING, "DEBUG: ")
@staticmethod
def info(text):
ColorPrint(text).write(ColorPrint.OKGREEN, "")
@staticmethod
def error(text):
ColorPrint(text).write(ColorPrint.FAIL + ColorPrint.BOLD, "")
@staticmethod
def summary(text):
ColorPrint(text).write(ColorPrint.OKGREEN + ColorPrint.UNDERLINE, "Summary: ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment