--- a/hgext/color.py Fri Jan 08 20:56:28 2010 +0100
+++ b/hgext/color.py Sat Jan 09 10:47:47 2010 +0100
@@ -18,8 +18,8 @@
'''colorize output from some commands
-This extension modifies the status command to add color to its output
-to reflect file status, the qseries command to add color to reflect
+This extension modifies the status and resolve commands to add color to their
+output to reflect file status, the qseries command to add color to reflect
patch status (applied, unapplied, missing), and to diff-related
commands to highlight additions, removals, diff headers, and trailing
whitespace.
@@ -57,6 +57,9 @@
diff.changed = white
diff.trailingwhitespace = bold red_background
+ resolve.unresolved = red bold
+ resolve.resolved = green bold
+
bookmarks.current = green
'''
@@ -95,14 +98,13 @@
stop = '\033[' + str(_effect_params['none']) + 'm'
return ''.join([start, text, stop])
-def colorstatus(orig, ui, repo, *pats, **opts):
- '''run the status command with colored output'''
-
- delimiter = opts['print0'] and '\0' or '\n'
+def _colorstatuslike(abbreviations, effectdefs, orig, ui, repo, *pats, **opts):
+ '''run a status-like command with colorized output'''
+ delimiter = opts.get('print0') and '\0' or '\n'
nostatus = opts.get('no_status')
opts['no_status'] = False
- # run status and capture its output
+ # run original command and capture its output
ui.pushbuffer()
retval = orig(ui, repo, *pats, **opts)
# filter out empty strings
@@ -115,13 +117,14 @@
# apply color to output and display it
for i in xrange(len(lines)):
- status = _status_abbreviations[lines_with_status[i][0]]
- effects = _status_effects[status]
+ status = abbreviations[lines_with_status[i][0]]
+ effects = effectdefs[status]
if effects:
lines[i] = render_effects(lines[i], effects)
ui.write(lines[i] + delimiter)
return retval
+
_status_abbreviations = { 'M': 'modified',
'A': 'added',
'R': 'removed',
@@ -140,6 +143,27 @@
'clean': ['none'],
'copied': ['none'], }
+def colorstatus(orig, ui, repo, *pats, **opts):
+ '''run the status command with colored output'''
+ return _colorstatuslike(_status_abbreviations, _status_effects,
+ orig, ui, repo, *pats, **opts)
+
+
+_resolve_abbreviations = { 'U': 'unresolved',
+ 'R': 'resolved', }
+
+_resolve_effects = { 'unresolved': ['red', 'bold'],
+ 'resolved': ['green', 'bold'], }
+
+def colorresolve(orig, ui, repo, *pats, **opts):
+ '''run the resolve command with colored output'''
+ if not opts.get('list'):
+ # only colorize for resolve -l
+ return orig(ui, repo, *pats, **opts)
+ return _colorstatuslike(_resolve_abbreviations, _resolve_effects,
+ orig, ui, repo, *pats, **opts)
+
+
_bookmark_effects = { 'current': ['green'] }
def colorbookmarks(orig, ui, repo, *pats, **opts):
@@ -270,6 +294,7 @@
_setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
_setupcmd(ui, 'tip', commands.table, None, _diff_effects)
_setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
+ _setupcmd(ui, 'resolve', commands.table, colorresolve, _resolve_effects)
try:
mq = extensions.find('mq')