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

login
register
mail settings
Submitter Sean Farley
Date April 7, 2014, 8:58 p.m.
Message ID <07cabc89783a8ce2fd22.1396904293@laptop.local>
Download mbox | patch
Permalink /patch/4244/
State Superseded
Commit 05086b56b56406962d26719bc9689a60e7f2e0f3
Headers show

Comments

Sean Farley - April 7, 2014, 8:58 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1396902796 18000
#      Mon Apr 07 15:33:16 2014 -0500
# Node ID 07cabc89783a8ce2fd224b2955fcce6e9ab90c38
# Parent  12f161f08d744f0e4b6eef9c905670afb5c24dd4
color: extract method for determining a valid effect
Matt Mackall - April 7, 2014, 9:09 p.m.
On Mon, 2014-04-07 at 15:58 -0500, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1396902796 18000
> #      Mon Apr 07 15:33:16 2014 -0500
> # Node ID 07cabc89783a8ce2fd224b2955fcce6e9ab90c38
> # Parent  12f161f08d744f0e4b6eef9c905670afb5c24dd4
> color: extract method for determining a valid effect
> 
> diff --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -309,10 +309,19 @@ def render_effects(text, effects):
>  
>  def extstyles():
>      for name, ext in extensions.extensions():
>          _styles.update(getattr(ext, 'colortable', {}))
>  
> +def valid_effect(effect):

http://mercurial.selenic.com/wiki/CodingStyle?action=show&redirect=BasicCodingStyle#Naming_conventions
Sean Farley - April 7, 2014, 9:14 p.m.
Matt Mackall <mpm@selenic.com> writes:

> On Mon, 2014-04-07 at 15:58 -0500, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@gmail.com>
>> # Date 1396902796 18000
>> #      Mon Apr 07 15:33:16 2014 -0500
>> # Node ID 07cabc89783a8ce2fd224b2955fcce6e9ab90c38
>> # Parent  12f161f08d744f0e4b6eef9c905670afb5c24dd4
>> color: extract method for determining a valid effect
>> 
>> diff --git a/hgext/color.py b/hgext/color.py
>> --- a/hgext/color.py
>> +++ b/hgext/color.py
>> @@ -309,10 +309,19 @@ def render_effects(text, effects):
>>  
>>  def extstyles():
>>      for name, ext in extensions.extensions():
>>          _styles.update(getattr(ext, 'colortable', {}))
>>  
>> +def valid_effect(effect):
>
> http://mercurial.selenic.com/wiki/CodingStyle?action=show&redirect=BasicCodingStyle#Naming_conventions

Fair enough. Though the other method names have underscores in them,
I'll remove it and resend.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -309,10 +309,19 @@  def render_effects(text, effects):
 
 def extstyles():
     for name, ext in extensions.extensions():
         _styles.update(getattr(ext, 'colortable', {}))
 
+def valid_effect(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)