changeset 31115:f5131d4f512a

color: move 'styles' definition on the 'ui' object Same logic as for '_terminfoparams'. The content depends on the config so it should be specific to each 'ui instance.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sun, 06 Nov 2016 20:16:01 +0100
parents 1613c55ad3d6
children 6483e49204ee
files hgext/color.py mercurial/color.py mercurial/ui.py
diffstat 3 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Sun Nov 06 20:10:53 2016 +0100
+++ b/hgext/color.py	Sun Nov 06 20:16:01 2016 +0100
@@ -207,31 +207,31 @@
         return _debugdisplaycolor(ui)
 
 def _debugdisplaycolor(ui):
-    oldstyle = color._styles.copy()
+    oldstyle = ui._styles.copy()
     try:
-        color._styles.clear()
+        ui._styles.clear()
         for effect in color._effects.keys():
-            color._styles[effect] = effect
+            ui._styles[effect] = effect
         if ui._terminfoparams:
             for k, v in ui.configitems('color'):
                 if k.startswith('color.'):
-                    color._styles[k] = k[6:]
+                    ui._styles[k] = k[6:]
                 elif k.startswith('terminfo.'):
-                    color._styles[k] = k[9:]
+                    ui._styles[k] = k[9:]
         ui.write(_('available colors:\n'))
         # sort label with a '_' after the other to group '_background' entry.
-        items = sorted(color._styles.items(),
+        items = sorted(ui._styles.items(),
                        key=lambda i: ('_' in i[0], i[0], i[1]))
         for colorname, label in items:
             ui.write(('%s\n') % colorname, label=label)
     finally:
-        color._styles.clear()
-        color._styles.update(oldstyle)
+        ui._styles.clear()
+        ui._styles.update(oldstyle)
 
 def _debugdisplaystyle(ui):
     ui.write(_('available style:\n'))
-    width = max(len(s) for s in color._styles)
-    for label, effects in sorted(color._styles.items()):
+    width = max(len(s) for s in ui._styles)
+    for label, effects in sorted(ui._styles.items()):
         ui.write('%s' % label, label=label)
         if effects:
             # 50
--- a/mercurial/color.py	Sun Nov 06 20:10:53 2016 +0100
+++ b/mercurial/color.py	Sun Nov 06 20:16:01 2016 +0100
@@ -254,6 +254,7 @@
     return None
 
 def configstyles(ui):
+    ui._styles.update(_styles)
     for status, cfgeffects in ui.configitems('color'):
         if '.' not in status or status.startswith(('color.', 'terminfo.')):
             continue
@@ -267,7 +268,7 @@
                     ui.warn(_("ignoring unknown color/effect %r "
                               "(configured in color.%s)\n")
                             % (e, status))
-            _styles[status] = ' '.join(good)
+            ui._styles[status] = ' '.join(good)
 
 def valideffect(ui, effect):
     'Determine if the effect is valid or not.'
@@ -321,7 +322,7 @@
     elif ui._colormode is not None:
         effects = []
         for l in label.split():
-            s = _styles.get(l, '')
+            s = ui._styles.get(l, '')
             if s:
                 effects.append(s)
             elif valideffect(ui, l):
@@ -443,7 +444,7 @@
 
         # determine console attributes based on labels
         for l in label.split():
-            style = _styles.get(l, '')
+            style = ui._styles.get(l, '')
             for effect in style.split():
                 try:
                     attr = mapcolor(w32effects[effect], attr)
--- a/mercurial/ui.py	Sun Nov 06 20:10:53 2016 +0100
+++ b/mercurial/ui.py	Sun Nov 06 20:16:01 2016 +0100
@@ -158,6 +158,7 @@
         # color mode: see mercurial/color.py for possible value
         self._colormode = None
         self._terminfoparams = {}
+        self._styles = {}
 
         if src:
             self.fout = src.fout
@@ -176,6 +177,7 @@
             self.insecureconnections = src.insecureconnections
             self._colormode = src._colormode
             self._terminfoparams = src._terminfoparams.copy()
+            self._styles = src._styles.copy()
 
             self.fixconfig()