diff options
Diffstat (limited to 'color.py')
| -rw-r--r-- | color.py | 21 |
1 files changed, 13 insertions, 8 deletions
| @@ -38,8 +38,11 @@ ATTRS = {None :-1, | |||
| 38 | 38 | ||
| 39 | RESET = "\033[m" | 39 | RESET = "\033[m" |
| 40 | 40 | ||
| 41 | def is_color(s): return s in COLORS | 41 | def is_color(s): |
| 42 | def is_attr(s): return s in ATTRS | 42 | return s in COLORS |
| 43 | |||
| 44 | def is_attr(s): | ||
| 45 | return s in ATTRS | ||
| 43 | 46 | ||
| 44 | def _Color(fg = None, bg = None, attr = None): | 47 | def _Color(fg = None, bg = None, attr = None): |
| 45 | fg = COLORS[fg] | 48 | fg = COLORS[fg] |
| @@ -80,8 +83,8 @@ def _Color(fg = None, bg = None, attr = None): | |||
| 80 | 83 | ||
| 81 | 84 | ||
| 82 | class Coloring(object): | 85 | class Coloring(object): |
| 83 | def __init__(self, config, type): | 86 | def __init__(self, config, section_type): |
| 84 | self._section = 'color.%s' % type | 87 | self._section = 'color.%s' % section_type |
| 85 | self._config = config | 88 | self._config = config |
| 86 | self._out = sys.stdout | 89 | self._out = sys.stdout |
| 87 | 90 | ||
| @@ -126,8 +129,8 @@ class Coloring(object): | |||
| 126 | if self._on: | 129 | if self._on: |
| 127 | c = self._parse(opt, fg, bg, attr) | 130 | c = self._parse(opt, fg, bg, attr) |
| 128 | def f(fmt, *args): | 131 | def f(fmt, *args): |
| 129 | str = fmt % args | 132 | output = fmt % args |
| 130 | return ''.join([c, str, RESET]) | 133 | return ''.join([c, output, RESET]) |
| 131 | return f | 134 | return f |
| 132 | else: | 135 | else: |
| 133 | def f(fmt, *args): | 136 | def f(fmt, *args): |
| @@ -151,8 +154,10 @@ class Coloring(object): | |||
| 151 | have_fg = False | 154 | have_fg = False |
| 152 | for a in v.split(' '): | 155 | for a in v.split(' '): |
| 153 | if is_color(a): | 156 | if is_color(a): |
| 154 | if have_fg: bg = a | 157 | if have_fg: |
| 155 | else: fg = a | 158 | bg = a |
| 159 | else: | ||
| 160 | fg = a | ||
| 156 | elif is_attr(a): | 161 | elif is_attr(a): |
| 157 | attr = a | 162 | attr = a |
| 158 | 163 | ||
