Mercurial > hg > index.fcgi > rcg > rcg-1
comparison rcg.py @ 13:2fb87616ab65
rcg.c: fix bug when dealing with ".*"
author | paulo@thepaulopc |
---|---|
date | Sat, 06 Nov 2010 02:57:06 -0700 |
parents | df03fa355b60 |
children | e618a3ff2027 |
comparison
equal
deleted
inserted
replaced
0:621762a49af3 | 1:075a3ba12b55 |
---|---|
26 } | 26 } |
27 | 27 |
28 bold = False | 28 bold = False |
29 fg = None | 29 fg = None |
30 bg = None | 30 bg = None |
31 colorLine = False | |
31 | 32 |
32 (optvals, args) = getopt.getopt(sys.argv[1:], "f:b:B") | 33 (optvals, args) = getopt.getopt(sys.argv[1:], "f:b:Bl") |
33 | 34 |
34 for (opt, val) in optvals: | 35 for (opt, val) in optvals: |
35 if opt == '-B': | 36 if opt == '-B': |
36 bold = True | 37 bold = True |
37 elif opt == '-f': | 38 elif opt == '-f': |
38 fg = val | 39 fg = val |
39 elif opt == '-b': | 40 elif opt == '-b': |
40 bg = val | 41 bg = val |
42 elif opt == '-l': | |
43 colorLine = True | |
41 | 44 |
42 if len(args) > 0: | 45 if len(args) > 0: |
43 for line in sys.stdin: | 46 for line in sys.stdin: |
44 repl = START | 47 repl = START |
45 if bold: | 48 if bold: |
47 if fg is not None: | 50 if fg is not None: |
48 repl += c[fg][0] | 51 repl += c[fg][0] |
49 if bg is not None: | 52 if bg is not None: |
50 repl += ';' + c[bg][1] | 53 repl += ';' + c[bg][1] |
51 repl += END + r'\1' + CLEAR | 54 repl += END + r'\1' + CLEAR |
52 x = re.sub(r'(' + args[0] + r')', repl, line) | 55 |
56 x = line | |
57 | |
58 if colorLine == False: | |
59 x = re.sub(r'(' + args[0] + r')', repl, line) | |
60 else: | |
61 if re.search(args[0], line) != None: | |
62 last_char = line[-1] | |
63 x = repl.replace(r'\1', line[:-1]) | |
64 x += last_char | |
53 | 65 |
54 sys.stdout.write(x) | 66 sys.stdout.write(x) |
55 sys.stdout.flush() | 67 sys.stdout.flush() |