[PATCH 4 of 8 simple] color: move 'valideffect' function into the core module

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Feb 15 06:06:16 EST 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1482370010 -3600
#      Thu Dec 22 02:26:50 2016 +0100
# Node ID bb59bec58bcdf57a3aeb1a9cd4a9b5b004c7c139
# Parent  b0ca5e9e8d9a6afa98accda7fcd5433ff19ddd1e
# EXP-Topic color
color: move 'valideffect' function into the core module

diff -r b0ca5e9e8d9a -r bb59bec58bcd hgext/color.py
--- a/hgext/color.py	Thu Dec 22 02:23:23 2016 +0100
+++ b/hgext/color.py	Thu Dec 22 02:26:50 2016 +0100
@@ -332,16 +332,6 @@ def render_effects(text, effects):
         stop = _effect_str('none')
     return ''.join([start, text, stop])
 
-def valideffect(effect):
-    'Determine if the effect is valid or not.'
-    good = False
-    if not color._terminfo_params and effect in color._effects:
-        good = True
-    elif (effect in color._terminfo_params
-          or effect[:-11] in color._terminfo_params):
-        good = True
-    return good
-
 def configstyles(ui):
     for status, cfgeffects in ui.configitems('color'):
         if '.' not in status or status.startswith(('color.', 'terminfo.')):
@@ -350,7 +340,7 @@ def configstyles(ui):
         if cfgeffects:
             good = []
             for e in cfgeffects:
-                if valideffect(e):
+                if color.valideffect(e):
                     good.append(e)
                 else:
                     ui.warn(_("ignoring unknown color/effect %r "
@@ -412,7 +402,7 @@ class colorui(uimod.ui):
             s = color._styles.get(l, '')
             if s:
                 effects.append(s)
-            elif valideffect(l):
+            elif color.valideffect(l):
                 effects.append(l)
         effects = ' '.join(effects)
         if effects:
diff -r b0ca5e9e8d9a -r bb59bec58bcd mercurial/color.py
--- a/mercurial/color.py	Thu Dec 22 02:23:23 2016 +0100
+++ b/mercurial/color.py	Thu Dec 22 02:26:50 2016 +0100
@@ -113,3 +113,13 @@ except ImportError:
 
 def loadcolortable(ui, extname, colortable):
     _styles.update(colortable)
+
+def valideffect(effect):
+    'Determine if the effect is valid or not.'
+    good = False
+    if not _terminfo_params and effect in _effects:
+        good = True
+    elif (effect in _terminfo_params
+          or effect[:-11] in _terminfo_params):
+        good = True
+    return good


More information about the Mercurial-devel mailing list