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