--- a/review/extension_ui.py Sat Feb 06 13:30:55 2010 +0100
+++ b/review/extension_ui.py Sat Feb 06 15:19:53 2010 +0100
@@ -6,10 +6,12 @@
"""
import operator, os
+import re
import messages
from api import *
from mercurial import help, templatefilters, util
from mercurial.node import short
+from mercurial import commands, extensions
def _web_command(ui, repo, **opts):
ui.note(messages.WEB_START)
@@ -213,8 +215,50 @@
)
for comment in skipped_comments:
_print_comment(comment)
-
+
+_review_effects = {'deleted': ['red'],
+ 'inserted': ['green'],
+ 'comments': ['cyan'],
+ }
+
+_review_re = [(re.compile(r'^(?P<rest> *\d+: )(?P<colorized>[-].*)'), 'deleted'),
+ (re.compile(r'^(?P<rest> *\d+: )(?P<colorized>[+].*)'), 'inserted'),
+ (re.compile(r'^(?P<colorized>#.*)'), 'comments'),]
+def colorwrap(orig, *args):
+ '''wrap ui.write for colored diff output'''
+ def _colorize(s):
+ lines = s.split('\n')
+ for i, line in enumerate(lines):
+ if not line:
+ continue
+ else:
+ for r, style in _review_re:
+ m = r.match(line)
+ if m:
+ lines[i] = "%s%s" % (m.groupdict().get('rest', ''),
+ render_effects(m.group('colorized'), _review_effects[style]))
+ break
+ return '\n'.join(lines)
+ orig(*[_colorize(s) for s in args])
+
+def colorreview(orig, ui, repo, *fnames, **opts):
+ '''colorize review command output'''
+ oldwrite = extensions.wrapfunction(ui, 'write', colorwrap)
+ try:
+ orig(ui, repo, *fnames, **opts)
+ finally:
+ ui.write = oldwrite
+
+def extsetup(ui):
+ try:
+ color = extensions.find('color')
+ color._setupcmd(ui, 'review', cmdtable, colorreview,
+ _review_effects)
+ global render_effects
+ render_effects = color.render_effects
+ except KeyError:
+ pass
def review(ui, repo, *fnames, **opts):
"""code review changesets in the current repository
@@ -369,4 +413,4 @@
hg review --signoff --yes --force -m 'Nevermind, this is fine.'
""")),
-)
\ No newline at end of file
+)