color: add ui to effect rendering
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Sat, 25 Feb 2017 15:00:44 +0100
changeset 31112 7f056fdbe37e
parent 31111 95ec3ad62f62
child 31113 268caf97c38f
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.
mercurial/color.py
--- 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