comparison rcg.py @ 6:910e059abd6d

rcg.c: fix bug with realloc()
author paulo@twcdns.fastsearch.net
date Tue, 06 Apr 2010 22:51:22 -0700
parents
children 6627edb46f36
comparison
equal deleted inserted replaced
-1:000000000000 0:621762a49af3
1 #!/usr/bin/env python
2
3 import sys
4 import re
5 import getopt
6
7 #x = "\x1B[1;31;49m" + x
8 #x = START + c["white"][0] + ";" + c["blue"][1] + END + x + CLEAR
9
10 START = "\x1B["
11 BOLD = "1;"
12 END = "m"
13 CLEAR = START + "0" + END
14
15 c = {
16 # color : (fg, bg)
17 "black" : ("30", "40"),
18 "red" : ("31", "41"),
19 "green" : ("32", "42"),
20 "brown" : ("33", "43"),
21 "blue" : ("34", "44"),
22 "magenta" : ("35", "45"),
23 "cyan" : ("36", "46"),
24 "white" : ("37", "47"),
25 "default" : ("39", "49"),
26 }
27
28 bold = False
29 fg = None
30 bg = None
31
32 (optvals, args) = getopt.getopt(sys.argv[1:], "f:b:B")
33
34 for (opt, val) in optvals:
35 if opt == '-B':
36 bold = True
37 elif opt == '-f':
38 fg = val
39 elif opt == '-b':
40 bg = val
41
42 if len(args) > 0:
43 for line in sys.stdin:
44 repl = START
45 if bold:
46 repl += BOLD
47 if fg is not None:
48 repl += c[fg][0]
49 if bg is not None:
50 repl += ';' + c[bg][1]
51 repl += END + r'\1' + CLEAR
52 x = re.sub(r'(' + args[0] + r')', repl, line)
53
54 sys.stdout.write(x)
55 sys.stdout.flush()