diff options
Diffstat (limited to 'color.py')
-rw-r--r-- | color.py | 65 |
1 files changed, 33 insertions, 32 deletions
@@ -36,50 +36,51 @@ ATTRS = {None :-1, | |||
36 | 'blink' : 5, | 36 | 'blink' : 5, |
37 | 'reverse': 7} | 37 | 'reverse': 7} |
38 | 38 | ||
39 | RESET = "\033[m" | 39 | RESET = "\033[m" # pylint: disable=W1401 |
40 | # backslash is not anomalous | ||
40 | 41 | ||
41 | def is_color(s): | 42 | def is_color(s): |
42 | return s in COLORS | 43 | return s in COLORS |
43 | 44 | ||
44 | def is_attr(s): | 45 | def is_attr(s): |
45 | return s in ATTRS | 46 | return s in ATTRS |
46 | 47 | ||
47 | def _Color(fg = None, bg = None, attr = None): | 48 | def _Color(fg = None, bg = None, attr = None): |
48 | fg = COLORS[fg] | 49 | fg = COLORS[fg] |
49 | bg = COLORS[bg] | 50 | bg = COLORS[bg] |
50 | attr = ATTRS[attr] | 51 | attr = ATTRS[attr] |
51 | 52 | ||
52 | if attr >= 0 or fg >= 0 or bg >= 0: | 53 | if attr >= 0 or fg >= 0 or bg >= 0: |
53 | need_sep = False | 54 | need_sep = False |
54 | code = "\033[" | 55 | code = "\033[" #pylint: disable=W1401 |
55 | 56 | ||
56 | if attr >= 0: | 57 | if attr >= 0: |
57 | code += chr(ord('0') + attr) | 58 | code += chr(ord('0') + attr) |
58 | need_sep = True | 59 | need_sep = True |
59 | 60 | ||
60 | if fg >= 0: | 61 | if fg >= 0: |
61 | if need_sep: | 62 | if need_sep: |
62 | code += ';' | 63 | code += ';' |
63 | need_sep = True | 64 | need_sep = True |
64 | 65 | ||
65 | if fg < 8: | 66 | if fg < 8: |
66 | code += '3%c' % (ord('0') + fg) | 67 | code += '3%c' % (ord('0') + fg) |
67 | else: | 68 | else: |
68 | code += '38;5;%d' % fg | 69 | code += '38;5;%d' % fg |
69 | 70 | ||
70 | if bg >= 0: | 71 | if bg >= 0: |
71 | if need_sep: | 72 | if need_sep: |
72 | code += ';' | 73 | code += ';' |
73 | need_sep = True | 74 | need_sep = True |
74 | 75 | ||
75 | if bg < 8: | 76 | if bg < 8: |
76 | code += '4%c' % (ord('0') + bg) | 77 | code += '4%c' % (ord('0') + bg) |
77 | else: | 78 | else: |
78 | code += '48;5;%d' % bg | 79 | code += '48;5;%d' % bg |
79 | code += 'm' | 80 | code += 'm' |
80 | else: | 81 | else: |
81 | code = '' | 82 | code = '' |
82 | return code | 83 | return code |
83 | 84 | ||
84 | 85 | ||
85 | class Coloring(object): | 86 | class Coloring(object): |