Last active
November 6, 2015 15:19
-
-
Save lucansky/79f2a8f43e0a2fb8a806 to your computer and use it in GitHub Desktop.
Python 3 color printer
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
# 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