Patchwork [3,of,7] color: add ui to effect rendering

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 27, 2017, 2:59 p.m.
Message ID <c6d19f0ac5ae80f93360.1488207599@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18804/
State Superseded
Headers show

Comments

Pierre-Yves David - Feb. 27, 2017, 2:59 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1488031244 -3600
#      Sat Feb 25 15:00:44 2017 +0100
# Node ID c6d19f0ac5ae80f933602fe217ff12ace828d02f
# Parent  c3224694bdae9cdb7530f952e2c767e419b7f280
# 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.

Patch

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -254,7 +254,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 "
@@ -262,13 +262,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
@@ -289,14 +289,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'
@@ -317,11 +317,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