diff rcg.py @ 11:6627edb46f36

add "color line" option to reference python implementation
author paulo@thepaulopc
date Sat, 06 Nov 2010 00:17:34 -0700
parents df03fa355b60
children e618a3ff2027
line diff
     1.1 --- a/rcg.py	Thu May 13 00:35:36 2010 -0700
     1.2 +++ b/rcg.py	Sat Nov 06 00:17:34 2010 -0700
     1.3 @@ -28,8 +28,9 @@
     1.4  bold = False
     1.5  fg = None
     1.6  bg = None
     1.7 +colorLine = False
     1.8  
     1.9 -(optvals, args) = getopt.getopt(sys.argv[1:], "f:b:B")
    1.10 +(optvals, args) = getopt.getopt(sys.argv[1:], "f:b:Bl")
    1.11  
    1.12  for (opt, val) in optvals:
    1.13  	if opt == '-B':
    1.14 @@ -38,6 +39,8 @@
    1.15  		fg = val
    1.16  	elif opt == '-b':
    1.17  		bg = val
    1.18 +	elif opt == '-l':
    1.19 +		colorLine = True
    1.20  
    1.21  if len(args) > 0:
    1.22  	for line in sys.stdin:
    1.23 @@ -49,7 +52,16 @@
    1.24  		if bg is not None:
    1.25  			repl += ';' + c[bg][1]
    1.26  		repl += END + r'\1' + CLEAR
    1.27 -		x = re.sub(r'(' + args[0] + r')', repl, line)
    1.28 +
    1.29 +		x = line
    1.30 +
    1.31 +		if colorLine == False:
    1.32 +			x = re.sub(r'(' + args[0] + r')', repl, line)
    1.33 +		else:
    1.34 +			if re.search(args[0], line) != None:
    1.35 +				last_char = line[-1]
    1.36 +				x = repl.replace(r'\1', line[:-1])
    1.37 +				x += last_char
    1.38  		
    1.39  		sys.stdout.write(x)
    1.40  		sys.stdout.flush()