# HG changeset patch # User Pierre-Yves David # Date 2017-02-23 18:10:24 # Node ID e6082078c8539803b924dcec90fe872bbd8ad3b4 # Parent 3422de9b657e79cfb60e23fcdc2b43a6420e4c13 color: move the 'colorlabel' function in the core module The extract code is relocated in core. diff --git a/hgext/color.py b/hgext/color.py --- a/hgext/color.py +++ b/hgext/color.py @@ -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 --git a/mercurial/color.py b/mercurial/color.py --- a/mercurial/color.py +++ b/mercurial/color.py @@ -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