Created
January 26, 2018 11:16
-
-
Save slavniyteo/935529a894eb72c88013752f10493be6 to your computer and use it in GitHub Desktop.
Small library to colorize you output. Based on https://github.com/vaniacer/bash_color
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
#!/usr/bin/env python2 | |
import os | |
if not('TERM' in os.environ): | |
os.exit() | |
#----------------------------------------------------------------------------+ | |
# Color picker, usage: | | |
# import pycolor as pc | | |
# print pc.BLD + pc.CUR + pc.RED + "Hello there!" + pc.DEF | | |
#-----------------------------+------------------------------------+---------+ | |
# Text color | Background color | | | |
#-------------+---------------+----------------+-------------------+ | | |
# Base color | Lighter shade | Base color | Lighter shade | | | |
#-------------+---------------+----------------+-------------------+ | | |
BLK='\033[30m'; blk='\033[90m'; BBLK='\033[40m'; bblk='\033[100m' #| Black | | |
RED='\033[31m'; red='\033[91m'; BRED='\033[41m'; bred='\033[101m' #| Red | | |
GRN='\033[32m'; grn='\033[92m'; BGRN='\033[42m'; bgrn='\033[102m' #| Green | | |
YLW='\033[33m'; ylw='\033[93m'; BYLW='\033[43m'; bylw='\033[103m' #| Yellow | | |
BLU='\033[34m'; blu='\033[94m'; BBLU='\033[44m'; bblu='\033[104m' #| Blue | | |
MGN='\033[35m'; mgn='\033[95m'; BMGN='\033[45m'; bmgn='\033[105m' #| Magenta | | |
CYN='\033[36m'; cyn='\033[96m'; BCYN='\033[46m'; bcyn='\033[106m' #| Cyan | | |
WHT='\033[37m'; wht='\033[97m'; BWHT='\033[47m'; bwht='\033[107m' #| White | | |
#------------------------------------------------------------------+---------+ | |
# Effects | | |
#----------------------------------------------------------------------------+ | |
DEF='\033[0m' #Default color and effects | | |
BLD='\033[1m' #Bold\brighter | | |
DIM='\033[2m' #Dim\darker | | |
CUR='\033[3m' #Italic font | | |
UND='\033[4m' #Underline | | |
INV='\033[7m' #Inverted | | |
COF='\033[?25l' #Cursor Off | | |
CON='\033[?25h' #Cursor On | | |
#----------------------------------------------------------------------------+ | |
# Text positioning, usage: pc.xy(10, 10, "Hello World!") | | |
def xy(x, y, text): # | | |
print "\033[%d;%dH%s" % (x, y, text) # | | |
#----------------------------------------------------------------------------+ | |
# Print line, usage: pc.line('-', 10) | pc.line('-=', 20, pc.RED) | | |
def line(symbol, length, color = ''): # | | |
print color + str(symbol) * length + DEF # | | |
#----------------------------------------------------------------------------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment