diff options
author | Erik Rose <grinch@grinchcentral.com> | 2018-08-18 21:01:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-18 21:01:49 -0400 |
commit | 0b81fe09469b6743e7467f6894dc036069c3a876 (patch) | |
tree | dbe32ee0a3e6b672a29badc626595783d59aba06 | |
parent | 015ad746a038d4a49d54b01bdf8892f6ebf17da0 (diff) | |
parent | 54727ec0aaac3773ed3237db7684522d12787e22 (diff) | |
download | blessings-0b81fe09469b6743e7467f6894dc036069c3a876.tar.gz |
Recognize negated capabilities in compound formatters. Close #135. Fix #134.
-rw-r--r-- | blessings/__init__.py | 13 | ||||
-rw-r--r-- | blessings/tests.py | 9 |
2 files changed, 17 insertions, 5 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py index 388cece..98b75c3 100644 --- a/blessings/__init__.py +++ b/blessings/__init__.py @@ -416,9 +416,11 @@ def derivative_colors(colors): COLORS = set(['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']) COLORS.update(derivative_colors(COLORS)) -COMPOUNDABLES = (COLORS | - set(['bold', 'underline', 'reverse', 'blink', 'dim', 'italic', - 'shadow', 'standout', 'subscript', 'superscript'])) +SINGLES = set(['bold', 'reverse', 'blink', 'dim', 'flash']) +DUALS = set([ + 'underline', 'italic', 'shadow', 'standout', 'subscript', 'superscript' +]) +COMPOUNDABLES = (COLORS | SINGLES | DUALS | set(['no_' + c for c in DUALS])) class ParametrizingString(text_type): @@ -543,11 +545,12 @@ def split_into_formatters(compound): >>> split_into_formatters('bold_underline_bright_blue_on_red') ['bold', 'underline', 'bright_blue', 'on_red'] - + >>> split_into_formatters('red_no_italic_shadow_on_bright_cyan') + ['red', 'no_italic', 'shadow', 'on_bright_cyan'] """ merged_segs = [] # These occur only as prefixes, so they can always be merged: - mergeable_prefixes = ['on', 'bright', 'on_bright'] + mergeable_prefixes = ['no', 'on', 'bright', 'on_bright'] for s in compound.split('_'): if merged_segs and merged_segs[-1] in mergeable_prefixes: merged_segs[-1] += '_' + s diff --git a/blessings/tests.py b/blessings/tests.py index a03eb8d..cf19cbb 100644 --- a/blessings/tests.py +++ b/blessings/tests.py @@ -210,6 +210,12 @@ def test_formatting_functions(): eq_(t.on_bright_red_bold_bright_green_underline('meh'), t.on_bright_red + t.bold + t.bright_green + t.underline + u'meh' + t.normal) + # Add also some negated vversions + eq_(t.bold_no_underline_green_on_red('boo'), + t.bold + t.no_underline + t.green + t.on_red + u'boo' + t.normal) + eq_(t.on_bright_red_no_italic_bright_green_underline('meh'), + t.on_bright_red + t.no_italic + t.bright_green + t.underline + + u'meh' + t.normal) def test_formatting_functions_without_tty(): @@ -221,6 +227,9 @@ def test_formatting_functions_without_tty(): eq_(t.bold_green(u'boö'), u'boö') eq_(t.bold_underline_green_on_red('loo'), u'loo') eq_(t.on_bright_red_bold_bright_green_underline('meh'), u'meh') + # Add some negated expressions + eq_(t.bold_no_underline_green_on_red('loo'), u'loo') + eq_(t.on_bright_red_bold_bright_green_no_underline('meh'), u'meh') def test_nice_formatting_errors(): |