changeset 9641:9b99f158348a

color: colorize diff --stat
author Brodie Rao <me+hg@dackz.net>
date Sun, 25 Oct 2009 02:52:36 +0200
parents 9e76232fbfbe
children 7d17794f08a9
files hgext/color.py tests/test-diff-color tests/test-diff-color.out
diffstat 3 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Sun Oct 25 02:52:35 2009 +0200
+++ b/hgext/color.py	Sun Oct 25 02:52:36 2009 +0200
@@ -189,9 +189,25 @@
     finally:
         self.ui.write = oldwrite
 
+def colordiffstat(orig, s):
+    lines = s.split('\n')
+    for i, line in enumerate(lines):
+        if line and line[-1] in '+-':
+            name, graph = line.rsplit(' ', 1)
+            graph = graph.replace('-',
+                        render_effects('-', _diff_effects['deleted']))
+            graph = graph.replace('+',
+                        render_effects('+', _diff_effects['inserted']))
+            lines[i] = ' '.join([name, graph])
+    orig('\n'.join(lines))
+
 def colordiff(orig, ui, repo, *pats, **opts):
     '''run the diff command with colored output'''
-    oldwrite = extensions.wrapfunction(ui, 'write', colorwrap)
+    if opts.get('stat'):
+        wrapper = colordiffstat
+    else:
+        wrapper = colorwrap
+    oldwrite = extensions.wrapfunction(ui, 'write', wrapper)
     try:
         orig(ui, repo, *pats, **opts)
     finally:
--- a/tests/test-diff-color	Sun Oct 25 02:52:35 2009 +0200
+++ b/tests/test-diff-color	Sun Oct 25 02:52:36 2009 +0200
@@ -35,6 +35,9 @@
 echo '% --unified=2'
 hg diff --nodates -U 2  --color=always
 
+echo '% diffstat'
+hg diff --stat --color=always
+
 echo "record=" >> $HGRCPATH
 echo "[ui]" >> $HGRCPATH
 echo "interactive=true" >> $HGRCPATH
--- a/tests/test-diff-color.out	Sun Oct 25 02:52:35 2009 +0200
+++ b/tests/test-diff-color.out	Sun Oct 25 02:52:36 2009 +0200
@@ -23,6 +23,9 @@
 +dd
  a
  a
+% diffstat
+ a |  2 +-
+ 1 files changed, 1 insertions(+), 1 deletions(-)
 % record
 diff --git a/a b/a
 old mode 100644