##// 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 b''
18
18
19 '''colorize output from some commands
19 '''colorize output from some commands
20
20
21 This extension modifies the status command to add color to its output
21 This extension modifies the status and resolve commands to add color to their
22 to reflect file status, the qseries command to add color to reflect
22 output to reflect file status, the qseries command to add color to reflect
23 patch status (applied, unapplied, missing), and to diff-related
23 patch status (applied, unapplied, missing), and to diff-related
24 commands to highlight additions, removals, diff headers, and trailing
24 commands to highlight additions, removals, diff headers, and trailing
25 whitespace.
25 whitespace.
@@ -57,6 +57,9 b' Default effects may be overridden from t'
57 diff.changed = white
57 diff.changed = white
58 diff.trailingwhitespace = bold red_background
58 diff.trailingwhitespace = bold red_background
59
59
60 resolve.unresolved = red bold
61 resolve.resolved = green bold
62
60 bookmarks.current = green
63 bookmarks.current = green
61 '''
64 '''
62
65
@@ -95,14 +98,13 b' def render_effects(text, effects):'
95 stop = '\033[' + str(_effect_params['none']) + 'm'
98 stop = '\033[' + str(_effect_params['none']) + 'm'
96 return ''.join([start, text, stop])
99 return ''.join([start, text, stop])
97
100
98 def colorstatus(orig, ui, repo, *pats, **opts):
101 def _colorstatuslike(abbreviations, effectdefs, orig, ui, repo, *pats, **opts):
99 '''run the status command with colored output'''
102 '''run a status-like command with colorized output'''
100
103 delimiter = opts.get('print0') and '\0' or '\n'
101 delimiter = opts['print0'] and '\0' or '\n'
102
104
103 nostatus = opts.get('no_status')
105 nostatus = opts.get('no_status')
104 opts['no_status'] = False
106 opts['no_status'] = False
105 # run status and capture its output
107 # run original command and capture its output
106 ui.pushbuffer()
108 ui.pushbuffer()
107 retval = orig(ui, repo, *pats, **opts)
109 retval = orig(ui, repo, *pats, **opts)
108 # filter out empty strings
110 # filter out empty strings
@@ -115,13 +117,14 b' def colorstatus(orig, ui, repo, *pats, *'
115
117
116 # apply color to output and display it
118 # apply color to output and display it
117 for i in xrange(len(lines)):
119 for i in xrange(len(lines)):
118 status = _status_abbreviations[lines_with_status[i][0]]
120 status = abbreviations[lines_with_status[i][0]]
119 effects = _status_effects[status]
121 effects = effectdefs[status]
120 if effects:
122 if effects:
121 lines[i] = render_effects(lines[i], effects)
123 lines[i] = render_effects(lines[i], effects)
122 ui.write(lines[i] + delimiter)
124 ui.write(lines[i] + delimiter)
123 return retval
125 return retval
124
126
127
125 _status_abbreviations = { 'M': 'modified',
128 _status_abbreviations = { 'M': 'modified',
126 'A': 'added',
129 'A': 'added',
127 'R': 'removed',
130 'R': 'removed',
@@ -140,6 +143,27 b' def colorstatus(orig, ui, repo, *pats, *'
140 'clean': ['none'],
143 'clean': ['none'],
141 'copied': ['none'], }
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 _bookmark_effects = { 'current': ['green'] }
167 _bookmark_effects = { 'current': ['green'] }
144
168
145 def colorbookmarks(orig, ui, repo, *pats, **opts):
169 def colorbookmarks(orig, ui, repo, *pats, **opts):
@@ -270,6 +294,7 b' def extsetup(ui):'
270 _setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
294 _setupcmd(ui, 'outgoing', commands.table, None, _diff_effects)
271 _setupcmd(ui, 'tip', commands.table, None, _diff_effects)
295 _setupcmd(ui, 'tip', commands.table, None, _diff_effects)
272 _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
296 _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects)
297 _setupcmd(ui, 'resolve', commands.table, colorresolve, _resolve_effects)
273
298
274 try:
299 try:
275 mq = extensions.find('mq')
300 mq = extensions.find('mq')
@@ -98,3 +98,23 b' assert "-q" "-u" 1'
98 assert "-m" "-a" 1
98 assert "-m" "-a" 1
99 assert "-r" "-d" 1
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 b' M modified'
132 R removed
132 R removed
133 ! deleted
133 ! deleted
134 ? unknown
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