Mercurial > hg-stable
changeset 7457:a70fb83cbb9e
diff colorization: finish highlighting trailing whitespace
author | Georg Brandl <georg@python.org> |
---|---|
date | Wed, 26 Nov 2008 22:58:07 +0100 |
parents | 79eb16db5e4a |
children | 03dd55115985 |
files | hgext/color.py |
diffstat | 1 files changed, 18 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/color.py Tue Dec 02 16:46:45 2008 +0100 +++ b/hgext/color.py Wed Nov 26 22:58:07 2008 +0100 @@ -21,11 +21,12 @@ This extension modifies the status command to add color to its 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. Other effects in -addition to color, like bold and underlined text, are also available. -Effects are rendered with the ECMA-48 SGR control function (aka ANSI escape -codes). This module also provides the render_text function, which can be -used to add effects to any text. +additions, removals, diff headers, and trailing whitespace. + +Other effects in addition to color, like bold and underlined text, are also +available. Effects are rendered with the ECMA-48 SGR control function (aka +ANSI escape codes). This module also provides the render_text function, +which can be used to add effects to any text. To enable this extension, add this to your .hgrc file: [extensions] @@ -57,7 +58,7 @@ diff.deleted = red diff.inserted = green diff.changed = white -diff.whitespace = bold red_background +diff.trailingwhitespace = bold red_background ''' import os, re, sys @@ -176,11 +177,17 @@ '''wrap ui.write for colored diff output''' lines = s.split('\n') for i, line in enumerate(lines): + stripline = line + if line and line[0] in '+-': + # highlight trailing whitespace, but only in changed lines + stripline = line.rstrip() for prefix, style in _diff_prefixes: - if line.startswith(prefix): - effects = _diff_effects[style] - lines[i] = render_effects(line, *_diff_effects[style]) + if stripline.startswith(prefix): + lines[i] = render_effects(stripline, *_diff_effects[style]) break + if line != stripline: + lines[i] += render_effects( + line[len(stripline):], *_diff_effects['trailingwhitespace']) orig('\n'.join(lines)) def colorshowpatch(orig, self, node): @@ -217,7 +224,8 @@ 'hunk': ('magenta',), 'deleted': ('red',), 'inserted': ('green',), - 'changed': ('white',)} + 'changed': ('white',), + 'trailingwhitespace': ('bold', 'red_background'),} def uisetup(ui): '''Initialize the extension.'''