Coverage for lasso/utils/console_coloring.py: 85%
34 statements
« prev ^ index » next coverage.py v7.2.4, created at 2023-04-28 18:42 +0100
« prev ^ index » next coverage.py v7.2.4, created at 2023-04-28 18:42 +0100
1class ConsoleColoring:
2 """Holds coloring escape sequences for command line shells"""
4 # text coloring
5 LIGHT_GREEN = "\033[92m"
6 LIGHT_RED = "\033[91m"
7 LIGHT_CYAN = "\033[96m"
8 LIGHT_BLUE = "\033[94m"
9 LIGHT_PURPLE = "\033[95m"
10 LIGHT_YELLOW = "\033[93m"
12 PURPLE = "\033[95m"
13 RED = "\033[91m"
14 GREEN = "\u001b[32m"
15 CYAN = "\u001b[36m"
16 WHITE = "\u001b[37m"
17 BLACK = "\u001b[30m"
18 BLUE = "\u001b[34m"
19 ORANGE = "\u001b[33m"
21 # special stuff
22 BOLD = "\033[1m"
23 UNDERLINE = "\033[4m"
24 REVERSED = "\u001b[7m"
26 # ends coloring
27 RESET = "\033[0m"
29 @staticmethod
30 def purple(msg, light=False):
31 """Format a string in purple
33 Parameters
34 ----------
35 msg : `str`
36 string to format
37 light : `bool`
38 whether to use light coloring
40 Returns
41 -------
42 formatted_msg : `str`
43 string colored for console output
44 """
45 return (
46 ConsoleColoring.LIGHT_PURPLE + msg + ConsoleColoring.RESET
47 if light
48 else ConsoleColoring.PURPLE + msg + ConsoleColoring.RESET
49 )
51 @staticmethod
52 def yellow(msg, light=False):
53 """Format a string in yellow
55 Parameters
56 ----------
57 msg : `str`
58 string to format
59 light : `bool`
60 whether to use light coloring
62 Returns
63 -------
64 formatted_msg : `str`
65 string colored for console output
66 """
67 return (
68 ConsoleColoring.LIGHT_YELLOW + msg + ConsoleColoring.RESET
69 if light
70 else ConsoleColoring.ORANGE + msg + ConsoleColoring.RESET
71 )
73 @staticmethod
74 def red(msg, light=False):
75 """Format a string in red
77 Parameters
78 ----------
79 msg : `str`
80 string to format
81 light : `bool`
82 whether to use light coloring
84 Returns
85 -------
86 formatted_msg : `str`
87 string colored for console output
88 """
89 return (
90 ConsoleColoring.LIGHT_RED + msg + ConsoleColoring.RESET
91 if light
92 else ConsoleColoring.RED + msg + ConsoleColoring.RESET
93 )
95 @staticmethod
96 def green(msg, light=False):
97 """Format a string in green
99 Parameters
100 ----------
101 msg : `str`
102 string to format
103 light : `bool`
104 whether to use light coloring
106 Returns
107 -------
108 formatted_msg : `str`
109 string colored for console output
110 """
111 return (
112 ConsoleColoring.LIGHT_GREEN + msg + ConsoleColoring.RESET
113 if light
114 else ConsoleColoring.GREEN + msg + ConsoleColoring.RESET
115 )
117 @staticmethod
118 def blue(msg, light=False):
119 """Format a string in green
121 Parameters
122 ----------
123 msg : `str`
124 string to format
125 light : `bool`
126 whether to use light coloring
128 Returns
129 -------
130 formatted_msg : `str`
131 string colored for console output
132 """
133 return (
134 ConsoleColoring.LIGHT_BLUE + msg + ConsoleColoring.RESET
135 if light
136 else ConsoleColoring.BLUE + msg + ConsoleColoring.RESET
137 )