changeset 31103:e6082078c853

color: move the 'colorlabel' function in the core module The extract code is relocated in core.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Thu, 23 Feb 2017 19:10:24 +0100
parents 3422de9b657e
children 894bdcdc75df
files hgext/color.py mercurial/color.py
diffstat 2 files changed, 23 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Thu Feb 23 19:00:26 2017 +0100
+++ b/hgext/color.py	Thu Feb 23 19:10:24 2017 +0100
@@ -331,29 +331,7 @@
     def label(self, msg, label):
         if self._colormode is None:
             return super(colorui, self).label(msg, label)
-        return colorlabel(self, msg, label)
-
-def colorlabel(ui, msg, label):
-    """add color control code according to the mode"""
-    if ui._colormode == 'debug':
-        if label and msg:
-            if msg[-1] == '\n':
-                msg = "[%s|%s]\n" % (label, msg[:-1])
-            else:
-                msg = "[%s|%s]" % (label, msg)
-    elif ui._colormode is not None:
-        effects = []
-        for l in label.split():
-            s = color._styles.get(l, '')
-            if s:
-                effects.append(s)
-            elif color.valideffect(l):
-                effects.append(l)
-        effects = ' '.join(effects)
-        if effects:
-            msg = '\n'.join([color._render_effects(line, effects)
-                             for line in msg.split('\n')])
-    return msg
+        return color.colorlabel(self, msg, label)
 
 def uisetup(ui):
     if ui.plain():
--- a/mercurial/color.py	Thu Feb 23 19:00:26 2017 +0100
+++ b/mercurial/color.py	Thu Feb 23 19:10:24 2017 +0100
@@ -175,6 +175,28 @@
         stop = '\033[' + str(_effects['none']) + 'm'
     return ''.join([start, text, stop])
 
+def colorlabel(ui, msg, label):
+    """add color control code according to the mode"""
+    if ui._colormode == 'debug':
+        if label and msg:
+            if msg[-1] == '\n':
+                msg = "[%s|%s]\n" % (label, msg[:-1])
+            else:
+                msg = "[%s|%s]" % (label, msg)
+    elif ui._colormode is not None:
+        effects = []
+        for l in label.split():
+            s = _styles.get(l, '')
+            if s:
+                effects.append(s)
+            elif valideffect(l):
+                effects.append(l)
+        effects = ' '.join(effects)
+        if effects:
+            msg = '\n'.join([_render_effects(line, effects)
+                             for line in msg.split('\n')])
+    return msg
+
 w32effects = None
 if pycompat.osname == 'nt':
     import ctypes