-
Notifications
You must be signed in to change notification settings - Fork 3
/
colorama_ansi.py
49 lines (39 loc) · 1.24 KB
/
colorama_ansi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
# taken from https://github.com/tartley/colorama/blob/master/colorama/ansi.py
# stripped down to only include foreground stuff
'''
This module generates ANSI character codes to printing colors to terminals.
See: http://en.wikipedia.org/wiki/ANSI_escape_code
'''
CSI = '\033['
def code_to_chars(code):
return CSI + str(code) + 'm'
class AnsiCodes(object):
def __init__(self):
# the subclasses declare class attributes which are numbers.
# Upon instantiation we define instance attributes, which are the same
# as the class attributes but wrapped with the ANSI escape sequence
for name in dir(self):
if not name.startswith('_'):
value = getattr(self, name)
setattr(self, name, code_to_chars(value))
class AnsiFore(AnsiCodes):
BLACK = 30
RED = 31
GREEN = 32
YELLOW = 33
BLUE = 34
MAGENTA = 35
CYAN = 36
WHITE = 37
RESET = 39
# These are fairly well supported, but not part of the standard.
LIGHTBLACK = 90
LIGHTRED = 91
LIGHTGREEN = 92
LIGHTYELLOW = 93
LIGHTBLUE = 94
LIGHTMAGENTA = 95
LIGHTCYAN = 96
LIGHTWHITE = 97
Fore = AnsiFore()