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