From patchwork Tue Feb 28 10:54:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [4,of,8,V2] color: add ui to effect rendering From: Pierre-Yves David X-Patchwork-Id: 18830 Message-Id: <39d07e7ccfaef5f4596c.1488279268@nodosa.octopoid.net> To: mercurial-devel@mercurial-scm.org Date: Tue, 28 Feb 2017 11:54:28 +0100 # HG changeset patch # User Pierre-Yves David # Date 1488031244 -3600 # Sat Feb 25 15:00:44 2017 +0100 # Node ID 39d07e7ccfaef5f4596ce919846fcccb207ec60f # Parent ed4cc3fba316882cda44f80bb143ebd32dd11bb1 # EXP-Topic color color: add ui to effect rendering We'll carry more and more color specific data on the ui object. This will help isolating different color configuration from each other. For example repository config might configure special style that should not affect other ui object. The first step is to make sure the ui object is available were we will needs it. diff --git a/mercurial/color.py b/mercurial/color.py --- a/mercurial/color.py +++ b/mercurial/color.py @@ -260,7 +260,7 @@ def configstyles(ui): if cfgeffects: good = [] for e in cfgeffects: - if valideffect(e): + if valideffect(ui, e): good.append(e) else: ui.warn(_("ignoring unknown color/effect %r " @@ -268,13 +268,13 @@ def configstyles(ui): % (e, status)) _styles[status] = ' '.join(good) -def valideffect(effect): +def valideffect(ui, effect): 'Determine if the effect is valid or not.' return ((not _terminfo_params and effect in _effects) or (effect in _terminfo_params or effect[:-11] in _terminfo_params)) -def _effect_str(effect): +def _effect_str(ui, effect): '''Helper function for render_effects().''' bg = False @@ -295,14 +295,14 @@ def _effect_str(effect): else: return curses.tparm(curses.tigetstr('setaf'), val) -def _render_effects(text, effects): +def _render_effects(ui, text, effects): 'Wrap text in commands to turn on each effect.' if not text: return text if _terminfo_params: - start = ''.join(_effect_str(effect) + start = ''.join(_effect_str(ui, effect) for effect in ['none'] + effects.split()) - stop = _effect_str('none') + stop = _effect_str(ui, 'none') else: start = [str(_effects[e]) for e in ['none'] + effects.split()] start = '\033[' + ';'.join(start) + 'm' @@ -323,11 +323,11 @@ def colorlabel(ui, msg, label): s = _styles.get(l, '') if s: effects.append(s) - elif valideffect(l): + elif valideffect(ui, l): effects.append(l) effects = ' '.join(effects) if effects: - msg = '\n'.join([_render_effects(line, effects) + msg = '\n'.join([_render_effects(ui, line, effects) for line in msg.split('\n')]) return msg