[PATCH 05 of 13 V2] color: move the 'colorlabel' call to the core 'ui' class

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Feb 24 17:09:39 EST 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1487875532 -3600
#      Thu Feb 23 19:45:32 2017 +0100
# Node ID fd0b7fed70ddeaf0568b02d5e0f9d982a68f1cb4
# Parent  13f7594f6a7e5cfd7092bcb197039c3c38e2e32f
# EXP-Topic color
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.

diff -r 13f7594f6a7e -r fd0b7fed70dd hgext/color.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 @@ class colorui(uimod.ui):
             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
diff -r 13f7594f6a7e -r fd0b7fed70dd mercurial/ui.py
--- 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 .i18n import _
 from .node import hex
 
 from . import (
+    color,
     config,
     encoding,
     error,
@@ -1361,13 +1362,15 @@ class ui(object):
     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 added the necessary control
+        character to apply such color. In addition 'debug' color mode adds
+        markup showing which label affect 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):


More information about the Mercurial-devel mailing list