comparison hgext/color.py @ 9551:3e698434b990

color: allow multiple args to ui.write()
author Kevin Bullock <kbullock@ringworld.org>
date Wed, 07 Oct 2009 14:01:20 -0500
parents 3bcb28131bab
children 9b99f158348a
comparison
equal deleted inserted replaced
9550:3bcb28131bab 9551:3e698434b990
160 return retval 160 return retval
161 161
162 _patch_effects = { 'applied': ['blue', 'bold', 'underline'], 162 _patch_effects = { 'applied': ['blue', 'bold', 'underline'],
163 'missing': ['red', 'bold'], 163 'missing': ['red', 'bold'],
164 'unapplied': ['black', 'bold'], } 164 'unapplied': ['black', 'bold'], }
165 def colorwrap(orig, s): 165 def colorwrap(orig, *args):
166 '''wrap ui.write for colored diff output''' 166 '''wrap ui.write for colored diff output'''
167 lines = s.split('\n') 167 def _colorize(s):
168 for i, line in enumerate(lines): 168 lines = s.split('\n')
169 stripline = line 169 for i, line in enumerate(lines):
170 if line and line[0] in '+-': 170 stripline = line
171 # highlight trailing whitespace, but only in changed lines 171 if line and line[0] in '+-':
172 stripline = line.rstrip() 172 # highlight trailing whitespace, but only in changed lines
173 for prefix, style in _diff_prefixes: 173 stripline = line.rstrip()
174 if stripline.startswith(prefix): 174 for prefix, style in _diff_prefixes:
175 lines[i] = render_effects(stripline, _diff_effects[style]) 175 if stripline.startswith(prefix):
176 break 176 lines[i] = render_effects(stripline, _diff_effects[style])
177 if line != stripline: 177 break
178 lines[i] += render_effects( 178 if line != stripline:
179 line[len(stripline):], _diff_effects['trailingwhitespace']) 179 lines[i] += render_effects(
180 orig('\n'.join(lines)) 180 line[len(stripline):], _diff_effects['trailingwhitespace'])
181 return '\n'.join(lines)
182 orig(*[_colorize(s) for s in args])
181 183
182 def colorshowpatch(orig, self, node): 184 def colorshowpatch(orig, self, node):
183 '''wrap cmdutil.changeset_printer.showpatch with colored output''' 185 '''wrap cmdutil.changeset_printer.showpatch with colored output'''
184 oldwrite = extensions.wrapfunction(self.ui, 'write', colorwrap) 186 oldwrite = extensions.wrapfunction(self.ui, 'write', colorwrap)
185 try: 187 try: