Mercurial > hg
diff mercurial/color.py @ 31086:e6082078c853
color: move the 'colorlabel' function in the core module
The extract code is relocated in core.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 23 Feb 2017 19:10:24 +0100 |
parents | 350d737e059d |
children | 75c4aafee490 |
line wrap: on
line diff
--- 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