changeset 31112:7f056fdbe37e

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.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sat, 25 Feb 2017 15:00:44 +0100
parents 95ec3ad62f62
children 268caf97c38f
files mercurial/color.py
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/color.py	Sat Feb 25 18:34:01 2017 +0100
+++ b/mercurial/color.py	Sat Feb 25 15:00:44 2017 +0100
@@ -260,7 +260,7 @@
         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 @@
                             % (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 @@
     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 @@
             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