still developing new md-coloring
This commit is contained in:
@@ -40,22 +40,50 @@ class ansi:
|
||||
so = '\033[29m'#strike off
|
||||
CLRLIN = '\033[2J'
|
||||
CLREND = '\033[K'
|
||||
CLRBEG = '\033[1K'
|
||||
CLRSCR = CLRLIN+"\033[0;0H"
|
||||
|
||||
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]
|
||||
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,CLRBEG,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,CLRBEG,CLRSCR]
|
||||
custom_match=re.compile(r'(\${)([0-9;]*[ABCDEFGHJKSTfminsu]+)(})')
|
||||
|
||||
def pos(self,y,x):
|
||||
""" Go to absolute position """
|
||||
return "\033["+str(y)+";"+str(x)+"H"
|
||||
def column(self,x):
|
||||
""" Go to absolute column """
|
||||
return "\033["+str(x)+"G"
|
||||
|
||||
def posprint(self, y,x,s):
|
||||
""" Print string at a location """
|
||||
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 clear_to_beginning(self):
|
||||
sys.stdout.write( self.CLRBEG )
|
||||
|
||||
def up(self,n=1):
|
||||
sys.stdout.write( "\033["+str(n)+"A" )
|
||||
def down(self,n=1):
|
||||
sys.stdout.write( "\033["+str(n)+"B" )
|
||||
def right(self,n=1):
|
||||
sys.stdout.write( "\033["+str(n)+"C" )
|
||||
def left(self,n=1):
|
||||
sys.stdout.write( "\033["+str(n)+"D" )
|
||||
def up_line(self,n=1):
|
||||
sys.stdout.write( "\033["+str(n)+"F" )
|
||||
def down_line(self,n=1):
|
||||
sys.stdout.write( "\033["+str(n)+"E" )
|
||||
|
||||
def save(self):
|
||||
""" Save cursor position """
|
||||
sys.stdout.write( "\033[s" )
|
||||
def restore(self):
|
||||
""" Restore cursor position """
|
||||
sys.stdout.write( "\033[u" )
|
||||
|
||||
def color_string(self,s):
|
||||
for i,c in enumerate(self.color_keys):
|
||||
@@ -64,8 +92,9 @@ class ansi:
|
||||
def nocolor_string(self,s):
|
||||
for i,c in enumerate(self.color_keys):
|
||||
s=s.replace("${"+c+"}","")
|
||||
return s
|
||||
return self.custom_nocolor(s)
|
||||
|
||||
def custom_color(self,s):
|
||||
return self.custom_match.sub('\033[\\2',s)
|
||||
|
||||
def custom_nocolor(self,s):
|
||||
return self.custom_match.sub('',s)
|
||||
|
||||
Reference in New Issue
Block a user