Created
November 3, 2012 11:04
-
-
Save martin-ueding/4007035 to your computer and use it in GitHub Desktop.
Python Colorcodes class
This file contains hidden or 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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
got it, looks like I was using thonny and had not set it up correctly