comparison hgext/color.py @ 7459:3fb5c142a9f0

color: replace effect-specific reset control codes with general purpose one
author Brodie Rao <me+hg@dackz.net>
date Mon, 01 Dec 2008 10:45:22 -0500
parents a70fb83cbb9e
children 92c373f8135f
comparison
equal deleted inserted replaced
7458:03dd55115985 7459:3fb5c142a9f0
65 65
66 from mercurial import cmdutil, commands, extensions 66 from mercurial import cmdutil, commands, extensions
67 from mercurial.i18n import _ 67 from mercurial.i18n import _
68 68
69 # start and stop parameters for effects 69 # start and stop parameters for effects
70 _effect_params = { 'none': (0, 0), 70 _effect_params = {'none': 0,
71 'black': (30, 39), 71 'black': 30,
72 'red': (31, 39), 72 'red': 31,
73 'green': (32, 39), 73 'green': 32,
74 'yellow': (33, 39), 74 'yellow': 33,
75 'blue': (34, 39), 75 'blue': 34,
76 'magenta': (35, 39), 76 'magenta': 35,
77 'cyan': (36, 39), 77 'cyan': 36,
78 'white': (37, 39), 78 'white': 37,
79 'bold': (1, 22), 79 'bold': 1,
80 'italic': (3, 23), 80 'italic': 3,
81 'underline': (4, 24), 81 'underline': 4,
82 'inverse': (7, 27), 82 'inverse': 7,
83 'black_background': (40, 49), 83 'black_background': 40,
84 'red_background': (41, 49), 84 'red_background': 41,
85 'green_background': (42, 49), 85 'green_background': 42,
86 'yellow_background': (43, 49), 86 'yellow_background': 43,
87 'blue_background': (44, 49), 87 'blue_background': 44,
88 'purple_background': (45, 49), 88 'purple_background': 45,
89 'cyan_background': (46, 49), 89 'cyan_background': 46,
90 'white_background': (47, 49), } 90 'white_background': 47}
91 91
92 def render_effects(text, *effects): 92 def render_effects(text, *effects):
93 'Wrap text in commands to turn on each effect.' 93 'Wrap text in commands to turn on each effect.'
94 start = [ str(_effect_params['none'][0]) ] 94 start = [str(_effect_params[e]) for e in ('none',) + effects]
95 stop = []
96 for effect in effects:
97 start.append(str(_effect_params[effect][0]))
98 stop.append(str(_effect_params[effect][1]))
99 stop.append(str(_effect_params['none'][1]))
100 start = '\033[' + ';'.join(start) + 'm' 95 start = '\033[' + ';'.join(start) + 'm'
101 stop = '\033[' + ';'.join(stop) + 'm' 96 stop = '\033[' + str(_effect_params['none']) + 'm'
102 return start + text + stop 97 return ''.join([start, text, stop])
103 98
104 def colorstatus(orig, ui, repo, *pats, **opts): 99 def colorstatus(orig, ui, repo, *pats, **opts):
105 '''run the status command with colored output''' 100 '''run the status command with colored output'''
106 101
107 delimiter = opts['print0'] and '\0' or '\n' 102 delimiter = opts['print0'] and '\0' or '\n'