changeset 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 f0417b6ff98a
files hgext/color.py
diffstat 1 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Thu Oct 08 09:27:22 2009 +0800
+++ b/hgext/color.py	Wed Oct 07 14:01:20 2009 -0500
@@ -162,22 +162,24 @@
 _patch_effects = { 'applied': ['blue', 'bold', 'underline'],
                     'missing': ['red', 'bold'],
                     'unapplied': ['black', 'bold'], }
-def colorwrap(orig, s):
+def colorwrap(orig, *args):
     '''wrap ui.write for colored diff output'''
-    lines = s.split('\n')
-    for i, line in enumerate(lines):
-        stripline = line
-        if line and line[0] in '+-':
-            # highlight trailing whitespace, but only in changed lines
-            stripline = line.rstrip()
-        for prefix, style in _diff_prefixes:
-            if stripline.startswith(prefix):
-                lines[i] = render_effects(stripline, _diff_effects[style])
-                break
-        if line != stripline:
-            lines[i] += render_effects(
-                line[len(stripline):], _diff_effects['trailingwhitespace'])
-    orig('\n'.join(lines))
+    def _colorize(s):
+        lines = s.split('\n')
+        for i, line in enumerate(lines):
+            stripline = line
+            if line and line[0] in '+-':
+                # highlight trailing whitespace, but only in changed lines
+                stripline = line.rstrip()
+            for prefix, style in _diff_prefixes:
+                if stripline.startswith(prefix):
+                    lines[i] = render_effects(stripline, _diff_effects[style])
+                    break
+            if line != stripline:
+                lines[i] += render_effects(
+                    line[len(stripline):], _diff_effects['trailingwhitespace'])
+        return '\n'.join(lines)
+    orig(*[_colorize(s) for s in args])
 
 def colorshowpatch(orig, self, node):
     '''wrap cmdutil.changeset_printer.showpatch with colored output'''