[PATCH 13 of 13] color: don't split colors across lines (which confuses less -R)
Brodie Rao
dackze at gmail.com
Wed Mar 31 10:00:49 CDT 2010
# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1270047130 18000
# Node ID d2a68bd7cf165ee9630b9b0aa13e8793b8d0b55e
# Parent fd16e66fc14da2f353f4c4d76a22bc06da218895
color: don't split colors across lines (which confuses less -R)
Currently, less -R doesn't support colors spanning multiple lines; only
the first line will be colorized.
Instead of allowing colors to span multiple lines, the color extension
now applies colors to each line it receives, even when ui.write() is
given multiple lines in one call.
diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -110,10 +110,7 @@ def render_effects(text, effects):
start = [str(_effects[e]) for e in ['none'] + effects.split()]
start = '\033[' + ';'.join(start) + 'm'
stop = '\033[' + str(_effects['none']) + 'm'
- if text[-1] == '\n':
- return ''.join([start, text[:-1], stop, '\n'])
- else:
- return ''.join([start, text, stop])
+ return ''.join([start, text, stop])
def extstyles():
for name, ext in extensions.extensions():
@@ -141,7 +138,8 @@ def style(msg, label):
for l in label.split():
effects += _styles.get(l, '')
if effects:
- return render_effects(msg, effects)
+ return '\n'.join([render_effects(s, effects)
+ for s in msg.split('\n')])
return msg
def popbuffer(orig, labeled=False):
diff --git a/tests/test-eolfilename.out b/tests/test-eolfilename.out
--- a/tests/test-eolfilename.out
+++ b/tests/test-eolfilename.out
@@ -14,7 +14,7 @@ f hell
o hell
o
% test issue2039
-[0;35;1;4m? foo
-bar[0m
-[0;35;1;4m? foo
-bar.baz[0m
+[0;35;1;4m? foo[0m
+[0;35;1;4mbar[0m
+[0;35;1;4m? foo[0m
+[0;35;1;4mbar.baz[0m
More information about the Mercurial-devel
mailing list