##// END OF EJS Templates
diff colorization: finish highlighting trailing whitespace
Georg Brandl -
r7457:a70fb83c default
parent child Browse files
Show More
@@ -21,11 +21,12 b''
21 21 This extension modifies the status command to add color to its output to
22 22 reflect file status, the qseries command to add color to reflect patch status
23 23 (applied, unapplied, missing), and to diff-related commands to highlight
24 additions, removals, diff headers, and trailing whitespace. Other effects in
25 addition to color, like bold and underlined text, are also available.
26 Effects are rendered with the ECMA-48 SGR control function (aka ANSI escape
27 codes). This module also provides the render_text function, which can be
28 used to add effects to any text.
24 additions, removals, diff headers, and trailing whitespace.
25
26 Other effects in addition to color, like bold and underlined text, are also
27 available. Effects are rendered with the ECMA-48 SGR control function (aka
28 ANSI escape codes). This module also provides the render_text function,
29 which can be used to add effects to any text.
29 30
30 31 To enable this extension, add this to your .hgrc file:
31 32 [extensions]
@@ -57,7 +58,7 b' diff.hunk = magenta'
57 58 diff.deleted = red
58 59 diff.inserted = green
59 60 diff.changed = white
60 diff.whitespace = bold red_background
61 diff.trailingwhitespace = bold red_background
61 62 '''
62 63
63 64 import os, re, sys
@@ -176,11 +177,17 b' def colorwrap(orig, s):'
176 177 '''wrap ui.write for colored diff output'''
177 178 lines = s.split('\n')
178 179 for i, line in enumerate(lines):
180 stripline = line
181 if line and line[0] in '+-':
182 # highlight trailing whitespace, but only in changed lines
183 stripline = line.rstrip()
179 184 for prefix, style in _diff_prefixes:
180 if line.startswith(prefix):
181 effects = _diff_effects[style]
182 lines[i] = render_effects(line, *_diff_effects[style])
185 if stripline.startswith(prefix):
186 lines[i] = render_effects(stripline, *_diff_effects[style])
183 187 break
188 if line != stripline:
189 lines[i] += render_effects(
190 line[len(stripline):], *_diff_effects['trailingwhitespace'])
184 191 orig('\n'.join(lines))
185 192
186 193 def colorshowpatch(orig, self, node):
@@ -217,7 +224,8 b' def colordiff(orig, ui, repo, *pats, **o'
217 224 'hunk': ('magenta',),
218 225 'deleted': ('red',),
219 226 'inserted': ('green',),
220 'changed': ('white',)}
227 'changed': ('white',),
228 'trailingwhitespace': ('bold', 'red_background'),}
221 229
222 230 def uisetup(ui):
223 231 '''Initialize the extension.'''
General Comments 0
You need to be logged in to leave comments. Login now