public
Last active

Python Colorcodes class

  • Download Gist
colorcodes.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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.
 
Control:
 
- bold
- reset
 
Colors:
 
- blue
- green
- orange
- red
 
:license: MIT
"""
def __init__(self):
try:
self.bold = subprocess.check_output("tput bold".split())
self.reset = subprocess.check_output("tput sgr0".split())
 
self.blue = subprocess.check_output("tput setaf 4".split())
self.green = subprocess.check_output("tput setaf 2".split())
self.orange = subprocess.check_output("tput setaf 3".split())
self.red = subprocess.check_output("tput setaf 1".split())
except subprocess.CalledProcessError as e:
self.bold = ""
self.reset = ""
 
self.blue = ""
self.green = ""
self.orange = ""
self.red = ""
 
_c = Colorcodes()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.