Patchwork [1,of,2,V4] color: extract method for determining a valid effect

login
register
mail settings
Submitter Sean Farley
Date April 7, 2014, 11:20 p.m.
Message ID <fe252f8b05c6a0e3b3ad.1396912800@laptop.local>
Download mbox | patch
Permalink /patch/4268/
State Accepted
Commit 05086b56b56406962d26719bc9689a60e7f2e0f3
Headers show

Comments

Sean Farley - April 7, 2014, 11:20 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1396902826 18000
#      Mon Apr 07 15:33:46 2014 -0500
# Node ID fe252f8b05c6a0e3b3ad4ed54d90c5bac07c0d6b
# Parent  12f161f08d744f0e4b6eef9c905670afb5c24dd4
color: extract method for determining a valid effect

This patch is just setup work so that we can reduce code duplication and have
one place to define a valid effect.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -309,21 +309,28 @@  def render_effects(text, effects):
 
 def extstyles():
     for name, ext in extensions.extensions():
         _styles.update(getattr(ext, '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
+
 def configstyles(ui):
     for status, cfgeffects in ui.configitems('color'):
         if '.' not in status or status.startswith('color.'):
             continue
         cfgeffects = ui.configlist('color', status)
         if cfgeffects:
             good = []
             for e in cfgeffects:
-                if not _terminfo_params and e in _effects:
-                    good.append(e)
-                elif e in _terminfo_params or e[:-11] in _terminfo_params:
+                if valideffect(e):
                     good.append(e)
                 else:
                     ui.warn(_("ignoring unknown color/effect %r "
                               "(configured in color.%s)\n")
                             % (e, status))