common replace rule, new coloring library
This commit is contained in:
60
reporting/bc.py
Normal file
60
reporting/bc.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# Python library for ansi colorization
|
||||
|
||||
class ansi:
|
||||
K="\033[1;30m"
|
||||
R="\033[1;31m"
|
||||
G="\033[1;32m"
|
||||
B="\033[1;34m"
|
||||
Y="\033[1;33m"
|
||||
M="\033[1;35m"
|
||||
C="\033[1;36m"
|
||||
W="\033[1;37m"
|
||||
|
||||
k="\033[0;30m"
|
||||
r="\033[0;31m"
|
||||
g="\033[0;32m"
|
||||
b="\033[0;34m"
|
||||
y="\033[0;33m"
|
||||
m="\033[0;35m"
|
||||
c="\033[0;36m"
|
||||
w="\033[0;37m"
|
||||
|
||||
bk="\033[40m"
|
||||
br="\033[41m"
|
||||
bg="\033[42m"
|
||||
by="\033[43m"
|
||||
bb="\033[44m"
|
||||
bm="\033[45m"
|
||||
bc="\033[46m"
|
||||
bw="\033[47m"
|
||||
|
||||
S = '\033[1m'#strong
|
||||
U = '\033[4m'#underline
|
||||
Z = '\033[0m'#zero colors
|
||||
CLRLIN = '\033[2J'
|
||||
CLREND = '\033[K'
|
||||
CLRSCR = CLRLIN+"\033[0;0H"
|
||||
|
||||
color_keys="K,R,G,B,Y,M,C,W,k,r,g,b,y,m,c,w,S,U,Z,bk,br,bg,by,bb,bm,bc,bw,CLRLIN,CLREND,CLRSCR".split(",")
|
||||
color_list=[K,R,G,B,Y,M,C,W,k,r,g,b,y,m,c,w,S,U,Z,bk,br,bg,by,bb,bm,bc,bw,CLRLIN,CLREND,CLRSCR]
|
||||
|
||||
def pos(self,y,x):
|
||||
return "\033["+str(y)+";"+str(x)+"H"
|
||||
|
||||
def posprint(self, y,x,s):
|
||||
sys.stdout.write( self.pos(y,x) + str(s) )
|
||||
|
||||
def clear(self):
|
||||
sys.stdout.write( self.CLR+self.pos(0,0) )
|
||||
def clear_to_end(self):
|
||||
sys.stdout.write( self.CLREND )
|
||||
|
||||
def color_string(self,s):
|
||||
for i,c in enumerate(self.color_keys):
|
||||
s=s.replace("${"+c+"}",self.color_list[i])
|
||||
return s
|
||||
def nocolor_string(self,s):
|
||||
for i,c in enumerate(self.color_keys):
|
||||
s=s.replace("${"+c+"}","")
|
||||
return s
|
||||
|
||||
Reference in New Issue
Block a user