Patchwork [04,of,13,V2] color: move the 'colorlabel' function in the core module

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 24, 2017, 10:09 p.m.
Message ID <13f7594f6a7e5cfd7092.1487974178@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18756/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 24, 2017, 10:09 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1487873424 -3600
#      Thu Feb 23 19:10:24 2017 +0100
# Node ID 13f7594f6a7e5cfd7092bcb197039c3c38e2e32f
# Parent  f7e501bba8311353d25762412670cfffb306a3b1
# EXP-Topic color
color: move the 'colorlabel' function in the core module

The extract code is relocated in core.

Patch

diff -r f7e501bba831 -r 13f7594f6a7e hgext/color.py
--- 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 @@  class colorui(uimod.ui):
     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():
diff -r f7e501bba831 -r 13f7594f6a7e mercurial/color.py
--- 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 @@  def _render_effects(text, effects):
         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