color: don't split colors across lines (which confuses less -R)
authorBrodie Rao <brodie@bitheap.org>
Fri, 02 Apr 2010 15:22:19 -0500
changeset 10827 b66388f6adfa
parent 10826 717c35d55fb3
child 10828 1aa9464ce9ae
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.
hgext/color.py
tests/test-eolfilename.out
--- a/hgext/color.py	Fri Apr 02 15:22:17 2010 -0500
+++ b/hgext/color.py	Fri Apr 02 15:22:19 2010 -0500
@@ -110,10 +110,7 @@
     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 @@
     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):
--- a/tests/test-eolfilename.out	Fri Apr 02 15:22:17 2010 -0500
+++ b/tests/test-eolfilename.out	Fri Apr 02 15:22:19 2010 -0500
@@ -14,7 +14,7 @@
 o  hell
 o
 % test issue2039
-? foo
-bar
-? foo
-bar.baz
+? foo
+bar
+? foo
+bar.baz