##// END OF EJS Templates
color: colorize output of hg resolve -l
Georg Brandl -
r10223:51421ab5 default
parent child Browse files
Show More
@@ -18,8 +18,8
18 18
19 19 '''colorize output from some commands
20 20
21 This extension modifies the status command to add color to its output
22 to reflect file status, the qseries command to add color to reflect
21 This extension modifies the status and resolve commands to add color to their
22 output to reflect file status, the qseries command to add color to reflect
23 23 patch status (applied, unapplied, missing), and to diff-related
24 24 commands to highlight additions, removals, diff headers, and trailing
25 25 whitespace.
@@ -57,6 +57,9 Default effects may be overridden from t
57 57 diff.changed = white
58 58 diff.trailingwhitespace = bold red_background
59 59
60 resolve.unresolved = red bold
61 resolve.resolved = green bold
62
60 63 bookmarks.current = green
61 64 '''
62 65
@@ -95,14 +98,13 def render_effects(text, effects):
95 98 stop = '\033[' + str(_effect_params['none']) + 'm'
96 99 return ''.join([start, text, stop])
97 100
98 def colorstatus(orig, ui, repo, *pats, **opts):
99 '''run the status command with colored output'''
100
101 delimiter = opts['print0'] and '\0' or '\n'
101 def _colorstatuslike(abbreviations, effectdefs, orig, ui, repo, *pats, **opts):
102 '''run a status-like command with colorized output'''
103 delimiter = opts.get('print0') and '\0' or '\n'
102 104
103 105 nostatus = opts.get('no_status')
104 106 opts['no_status'] = False
105 # run status and capture its output
107 # run original command and capture its output
106 108 ui.pushbuffer()
107 109 retval = orig(ui, repo, *pats, **opts)
108 110 # filter out empty strings
@@ -115,13 +117,14 def colorstatus(orig, ui, repo, *pats, *
115 117
116 118 # apply color to output and display it
117 119 for i in xrange(len(lines)):
118 status = _status_abbreviations[lines_with_status[i][0]]
119 effects = _status_effects[status]
120 status = abbreviations[lines_with_status[i][0]]
121 effects = effectdefs[status]
120 122 if effects:
121 123 lines[i] = render_effects(lines[i], effects)
122 124 ui.write(lines[i] + delimiter)
123 125 return retval
124 126
127
125 128 _status_abbreviations = { 'M': 'modified',
126 129 'A': 'added',
127 130 'R': 'removed',
@@ -140,6 +143,27 def colorstatus(orig, ui, repo, *pats, *
140 143 'clean': ['none'],
141 144 'copied': ['none'], }
142 145
146 def colorstatus(orig, ui, repo, *pats, **opts):
147 '''run the status command with colored output'''
148 return _colorstatuslike(_status_abbreviations, _status_effects,
149 orig, ui, repo, *pats, **opts)
150
151
152 _resolve_abbreviations = { 'U': 'unresolved',
153 'R': 'resolved', }
154
155 _resolve_effects = { 'unresolved': ['red', 'bold'],
156 'resolved': ['green', 'bold'], }
157
158 def colorresolve(orig, ui, repo, *pats, **opts):
159 '''run the resolve command with colored output'''
160 if not opts.get('list'):
161 # only colorize for resolve -l
162 return orig(ui, repo, *pats, **opts)
163 return _colorstatuslike(_resolve_abbreviations, _resolve_effects,
164 orig, ui, repo, *pats, **opts)
165
166
143 167 _bookmark_effects = { 'current': ['green'] }
144 168
145 169 def colorbookmarks(orig, ui, repo, *pats, **opts):
@@ -270,6 +294,7 def extsetup(ui):
270 294 _setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
271 295 _setupcmd(ui, 'tip', commands.table, None, _diff_effects)
272 296 _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
297 _setupcmd(ui, 'resolve', commands.table, colorresolve, _resolve_effects)
273 298
274 299 try:
275 300 mq = extensions.find('mq')
@@ -98,3 +98,23 assert "-q" "-u" 1
98 98 assert "-m" "-a" 1
99 99 assert "-r" "-d" 1
100 100
101 cd ..
102
103 # test 'resolve -l'
104 hg init repo4
105 cd repo4
106 echo "file a" > a
107 echo "file b" > b
108 hg add a b
109 hg commit -m "initial"
110 echo "file a change 1" > a
111 echo "file b change 1" > b
112 hg commit -m "head 1"
113 hg update 0
114 echo "file a change 2" > a
115 echo "file b change 2" > b
116 hg commit -m "head 2"
117 hg merge
118 hg resolve -m b
119 echo "hg resolve with one unresolved, one resolved:"
120 hg resolve --color=always -l
@@ -132,3 +132,16 M modified
132 132 R removed
133 133 ! deleted
134 134 ? unknown
135 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
136 created new head
137 merging a
138 warning: conflicts during merge.
139 merging a failed!
140 merging b
141 warning: conflicts during merge.
142 merging b failed!
143 0 files updated, 0 files merged, 0 files removed, 2 files unresolved
144 use 'hg resolve' to retry unresolved file merges or 'hg update -C' to abandon
145 hg resolve with one unresolved, one resolved:
146 U a
147 R b
General Comments 0
You need to be logged in to leave comments. Login now