color: move the 'colorlabel' call to the core 'ui' class
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 23 Feb 2017 19:45:32 +0100
changeset 31087 894bdcdc75df
parent 31086 e6082078c853
child 31088 75c4aafee490
color: move the 'colorlabel' call to the core 'ui' class This bring us closer to supporting color in core natively. Core already have a 'label' method that was a no-op. We update its to call the new 'colorlabel' function. Behavior is unchanged when colormode = None.
hgext/color.py
mercurial/ui.py
--- a/hgext/color.py	Thu Feb 23 19:10:24 2017 +0100
+++ b/hgext/color.py	Thu Feb 23 19:45:32 2017 +0100
@@ -328,11 +328,6 @@
             return super(colorui, self).write_err(
                 *[self.label(a, label) for a in args], **opts)
 
-    def label(self, msg, label):
-        if self._colormode is None:
-            return super(colorui, self).label(msg, label)
-        return color.colorlabel(self, msg, label)
-
 def uisetup(ui):
     if ui.plain():
         return
--- a/mercurial/ui.py	Thu Feb 23 19:10:24 2017 +0100
+++ b/mercurial/ui.py	Thu Feb 23 19:45:32 2017 +0100
@@ -26,6 +26,7 @@
 from .node import hex
 
 from . import (
+    color,
     config,
     encoding,
     error,
@@ -1364,13 +1365,15 @@
     def label(self, msg, label):
         '''style msg based on supplied label
 
-        Like ui.write(), this just returns msg unchanged, but extensions
-        and GUI tools can override it to allow styling output without
-        writing it.
+        If some color mode is enabled, this will add the necessary control
+        characters to apply such color. In addition, 'debug' color mode adds
+        markup showing which label affects a piece of text.
 
         ui.write(s, 'label') is equivalent to
         ui.write(ui.label(s, 'label')).
         '''
+        if self._colormode is not None:
+            return color.colorlabel(self, msg, label)
         return msg
 
     def develwarn(self, msg, stacklevel=1, config=None):