Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python Colorcodes class
class Colorcodes(object):
Provides ANSI terminal color codes which are gathered via the ``tput``
utility. That way, they are portable. If there occurs any error with
``tput``, all codes are initialized as an empty string.
The provides fields are listed below.
- bold
- reset
- blue
- green
- orange
- red
:license: MIT
def __init__(self):
self.bold = subprocess.check_output("tput bold".split())
self.reset = subprocess.check_output("tput sgr0".split()) = subprocess.check_output("tput setaf 4".split()) = subprocess.check_output("tput setaf 2".split()) = subprocess.check_output("tput setaf 3".split()) = subprocess.check_output("tput setaf 1".split())
except subprocess.CalledProcessError as e:
self.bold = ""
self.reset = "" = "" = "" = "" = ""
_c = Colorcodes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment