Mercurial > hg
changeset 31085:3422de9b657e
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.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 23 Feb 2017 19:00:26 +0100 |
parents | 1482b57701ad |
children | e6082078c853 |
files | hgext/color.py |
diffstat | 1 files changed, 12 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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():