Last active
August 29, 2015 14:19
-
-
Save mirekfranc/4b80080d14aa35db42d2 to your computer and use it in GitHub Desktop.
How to do colors in terminal from within python script
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
#!/usr/bin/env python | |
import sys, os | |
from collections import namedtuple | |
Color = namedtuple ("Color", "PURPLE CYAN DARKCYAN BLUE GREEN YELLOW RED BOLD UNDERLINE END") | |
color = Color ('\033[95m', '\033[96m', '\033[36m', '\033[94m', '\033[92m', '\033[93m', '\033[91m', '\033[1m', '\033[4m', '\033[0m') | |
def main (): | |
output = sys.stdout | |
if not os.isatty (output.fileno ()): | |
global color | |
color = Color ('', '', '', '', '', '', '', '', '', '') | |
output.write (color.RED + "hello, world" + color.END + "\n") | |
if __name__ == "__main__": | |
main () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment