[PATCH 2 of 2] color: don't split colors across lines (confuses less -R)

Brodie Rao dackze at gmail.com
Fri Mar 26 14:14:17 CDT 2010


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1269630600 14400
# Node ID 8b0d3e5924e10b32e6aa2f275bed7476d97c5043
# Parent  c5eaa1e8207881ad48aaeaf98fcd642bdb6c76b3
color: don't split colors across lines (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
-? foo
-bar
-? foo
-bar.baz
+? foo
+bar
+? foo
+bar.baz


More information about the Mercurial-devel mailing list