Mercurial > hg
diff hgext/color.py @ 9641:9b99f158348a
color: colorize diff --stat
author | Brodie Rao <me+hg@dackz.net> |
---|---|
date | Sun, 25 Oct 2009 02:52:36 +0200 |
parents | 3e698434b990 |
children | d29bd00bbc50 |
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: