-
Notifications
You must be signed in to change notification settings - Fork 74
/
colors.py
68 lines (54 loc) · 2.13 KB
/
colors.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# coding: utf-8
from colorama import Fore, Style
class Color(object):
""" Helper for highlighting a console tools """
try:
CLS_YELLOW = Fore.LIGHTYELLOW_EX
CLS_GREY = Fore.LIGHTBLACK_EX
except AttributeError:
CLS_YELLOW = Fore.YELLOW
CLS_GREY = Fore.CYAN
COLORS_NODE = {
0: Fore.GREEN,
1: Fore.RED,
2: CLS_YELLOW,
3: Fore.BLUE,
-1: Style.RESET_ALL,
}
COLORS_SOCKET = {
0: Fore.BLUE,
1: CLS_YELLOW,
2: Fore.RED,
3: Fore.GREEN,
-1: Style.RESET_ALL,
}
COLOR_NONE = dict((key, "") for key in range(-1, 4))
def __init__(self, topology, enabled):
self.enabled, self.topology = enabled, topology
self.RESET, self.RESET_ALL = Fore.RESET, Style.RESET_ALL
self.YELLOW, self.GREY = Color.CLS_YELLOW, Color.CLS_GREY
self.RED, self.BRIGHT = Fore.RED, Style.BRIGHT
self.color_scheme = self.__choose_color_scheme()
def __choose_color_scheme(self):
if not self.enabled or not self.topology:
self.BRIGHT = self.RESET_ALL = self.RED = self.RESET = self.GREY = self.YELLOW = ""
return self.COLOR_NONE
if self.topology.layout_kind == 'NUMA':
return self.COLORS_NODE
return self.COLORS_SOCKET
def wrap(self, word, color):
""" wrap string in given color """
return '{0}{1}{2}'.format(color, word, self.RESET_ALL)