diff options
author | Andres Ayala <killerrex@gmail.com> | 2018-08-10 00:22:08 +0200 |
---|---|---|
committer | Andres Ayala <killerrex@gmail.com> | 2018-08-10 00:22:08 +0200 |
commit | 54727ec0aaac3773ed3237db7684522d12787e22 (patch) | |
tree | dbe32ee0a3e6b672a29badc626595783d59aba06 /blessings/__init__.py | |
parent | 015ad746a038d4a49d54b01bdf8892f6ebf17da0 (diff) | |
download | blessings-54727ec0aaac3773ed3237db7684522d12787e22.tar.gz |
Recognize correctly the negated form of the capabilities.
This patch introduces 2 main changes:
- COMPOUNDABLES includes the negated version of the 'underline',
'italic'... so now it includes also 'no_italic' and similar.
- split_into_formatters considers also the 'no' prefix.
With this changes expressions like:
t.red_no_underline
t.no_italic_bright_yellow
work as expected.
Diffstat (limited to 'blessings/__init__.py')
-rw-r--r-- | blessings/__init__.py | 13 |
1 files changed, 8 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 |