# HG changeset patch # User Pierre-Yves David # Date 1487872826 -3600 # Node ID 3422de9b657e79cfb60e23fcdc2b43a6420e4c13 # Parent 1482b57701add64f3668708dabf11cf1d3f68271 color: extract the label code into its own function We extract the logic into a function. This will allow us to move the logic into the core 'color' module and later call it directly from core. diff -r 1482b57701ad -r 3422de9b657e hgext/color.py --- a/hgext/color.py Mon Feb 20 12:13:23 2017 +0100 +++ b/hgext/color.py Thu Feb 23 19:00:26 2017 +0100 @@ -331,16 +331,17 @@ def label(self, msg, label): if self._colormode is None: return super(colorui, self).label(msg, label) + return colorlabel(self, msg, label) - if self._colormode == 'debug': - if label and msg: - if msg[-1] == '\n': - return "[%s|%s]\n" % (label, msg[:-1]) - else: - return "[%s|%s]" % (label, msg) +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: - return msg - + msg = "[%s|%s]" % (label, msg) + elif ui._colormode is not None: effects = [] for l in label.split(): s = color._styles.get(l, '') @@ -350,9 +351,9 @@ effects.append(l) effects = ' '.join(effects) if effects: - return '\n'.join([color._render_effects(line, effects) - for line in msg.split('\n')]) - return msg + msg = '\n'.join([color._render_effects(line, effects) + for line in msg.split('\n')]) + return msg def uisetup(ui): if ui.plain():