# HG changeset patch # User paulo@thepaulopc # Date 1289027854 25200 # Node ID 6627edb46f36b28c8adc8a1d1b9b7ea382cb62c8 # Parent 4ef47c3bdce6c68efab4e696dfe498dc4f6edbfb add "color line" option to reference python implementation diff -r 4ef47c3bdce6 -r 6627edb46f36 rcg.py --- a/rcg.py Thu May 13 00:35:36 2010 -0700 +++ b/rcg.py Sat Nov 06 00:17:34 2010 -0700 @@ -28,8 +28,9 @@ bold = False fg = None bg = None +colorLine = False -(optvals, args) = getopt.getopt(sys.argv[1:], "f:b:B") +(optvals, args) = getopt.getopt(sys.argv[1:], "f:b:Bl") for (opt, val) in optvals: if opt == '-B': @@ -38,6 +39,8 @@ fg = val elif opt == '-b': bg = val + elif opt == '-l': + colorLine = True if len(args) > 0: for line in sys.stdin: @@ -49,7 +52,16 @@ if bg is not None: repl += ';' + c[bg][1] repl += END + r'\1' + CLEAR - x = re.sub(r'(' + args[0] + r')', repl, line) + + x = line + + if colorLine == False: + x = re.sub(r'(' + args[0] + r')', repl, line) + else: + if re.search(args[0], line) != None: + last_char = line[-1] + x = repl.replace(r'\1', line[:-1]) + x += last_char sys.stdout.write(x) sys.stdout.flush()