more development to coloring
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# Python library for ansi colorization
|
||||
import re
|
||||
|
||||
class ansi:
|
||||
K="\033[1;30m"
|
||||
@@ -29,15 +30,22 @@ class ansi:
|
||||
bw="\033[47m"
|
||||
|
||||
S = '\033[1m'#strong
|
||||
s = '\033[2m'#strong off
|
||||
U = '\033[4m'#underline
|
||||
u = '\033[24m'#underline off
|
||||
Z = '\033[0m'#zero colors
|
||||
ic = '\033[7m'#inverse colors
|
||||
io = '\033[27m'#inverse off
|
||||
st = '\033[9m'#strike on
|
||||
so = '\033[29m'#strike off
|
||||
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]
|
||||
|
||||
color_keys="K,R,G,B,Y,M,C,W,k,r,g,b,y,m,c,w,S,s,U,u,Z,ic,io,st,so,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,s,U,u,Z,ic,io,st,so,bk,br,bg,by,bb,bm,bc,bw,CLRLIN,CLREND,CLRSCR]
|
||||
custom_match=re.compile(r'(\${)([0-9;]*[ABCDEFGHJKSTfminsu]+)(})')
|
||||
|
||||
def pos(self,y,x):
|
||||
return "\033["+str(y)+";"+str(x)+"H"
|
||||
|
||||
@@ -52,9 +60,12 @@ class ansi:
|
||||
def color_string(self,s):
|
||||
for i,c in enumerate(self.color_keys):
|
||||
s=s.replace("${"+c+"}",self.color_list[i])
|
||||
return s
|
||||
return self.custom_color(s)
|
||||
def nocolor_string(self,s):
|
||||
for i,c in enumerate(self.color_keys):
|
||||
s=s.replace("${"+c+"}","")
|
||||
return s
|
||||
|
||||
def custom_color(self,s):
|
||||
return self.custom_match.sub('\033[\\2',s)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user