# HG changeset patch # User Pierre-Yves David # Date 1487873424 -3600 # Node ID e6082078c8539803b924dcec90fe872bbd8ad3b4 # Parent 3422de9b657e79cfb60e23fcdc2b43a6420e4c13 color: move the 'colorlabel' function in the core module The extract code is relocated in core. diff -r 3422de9b657e -r e6082078c853 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 @@ 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 3422de9b657e -r e6082078c853 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 @@ 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