|
15 | 15 |
|
16 | 16 | from colorama import Fore, Style, init |
17 | 17 |
|
18 | | -# Initialize colorama for cross-platform support |
19 | | -init() |
20 | | - |
21 | 18 | # Status symbols |
22 | 19 | CHECK_MARK = '✓' |
23 | 20 |
|
24 | 21 |
|
25 | 22 | class ColorUtils: |
26 | 23 | """Utility class for applying colors to text using colorama.""" |
27 | 24 |
|
28 | | - @staticmethod |
29 | | - def make_green(text, use_color=True): |
| 25 | + def __init__(self): |
| 26 | + # Initialize colorama |
| 27 | + init(autoreset=True, strip=False) |
| 28 | + |
| 29 | + def make_green(self, text, use_color=True): |
30 | 30 | if not use_color: |
31 | 31 | return text |
32 | 32 | return f"{Fore.GREEN}{text}{Style.RESET_ALL}" |
33 | 33 |
|
34 | | - @staticmethod |
35 | | - def make_red(text, use_color=True): |
| 34 | + def make_red(self, text, use_color=True): |
36 | 35 | if not use_color: |
37 | 36 | return text |
38 | 37 | return f"{Fore.RED}{text}{Style.RESET_ALL}" |
39 | 38 |
|
40 | | - @staticmethod |
41 | | - def make_purple(text, use_color=True): |
| 39 | + def make_purple(self, text, use_color=True): |
42 | 40 | if not use_color: |
43 | 41 | return text |
44 | 42 | return f"{Fore.MAGENTA}{text}{Style.RESET_ALL}" |
45 | 43 |
|
46 | | - @staticmethod |
47 | | - def make_yellow(text, use_color=True): |
| 44 | + def make_yellow(self, text, use_color=True): |
48 | 45 | if not use_color: |
49 | 46 | return text |
50 | 47 | return f"{Fore.YELLOW}{text}{Style.RESET_ALL}" |
51 | 48 |
|
52 | | - @staticmethod |
53 | | - def make_cyan(text, use_color=True): |
| 49 | + def make_cyan(self, text, use_color=True): |
54 | 50 | if not use_color: |
55 | 51 | return text |
56 | 52 | return f"{Fore.CYAN}{text}{Style.RESET_ALL}" |
57 | 53 |
|
58 | | - @staticmethod |
59 | | - def color_by_status(text, status, use_color=True): |
| 54 | + def color_by_status(self, text, status, use_color=True): |
60 | 55 | """Color text based on resource status.""" |
61 | 56 | if not status or status == "ACTIVE" or status == "SUCCESSFUL": |
62 | | - return ColorUtils.make_green(text, use_color) |
| 57 | + return self.make_green(text, use_color) |
63 | 58 | elif status == "FAILED": |
64 | | - return ColorUtils.make_red(text, use_color) |
| 59 | + return self.make_red(text, use_color) |
65 | 60 | elif status == "DELETED": |
66 | | - return ColorUtils.make_yellow(text, use_color) |
| 61 | + return self.make_yellow(text, use_color) |
67 | 62 | else: |
68 | | - return ColorUtils.make_purple(text, use_color) |
| 63 | + return self.make_purple(text, use_color) |
69 | 64 |
|
70 | | - @staticmethod |
71 | | - def make_status_symbol(status, spinner_char, use_color=True): |
| 65 | + def make_status_symbol(self, status, spinner_char, use_color=True): |
72 | 66 | """Create status symbol with appropriate color.""" |
73 | 67 | if not status or status == "ACTIVE" or status == "SUCCESSFUL": |
74 | | - return ColorUtils.make_green(f"{CHECK_MARK} ", use_color) |
| 68 | + return self.make_green(f"{CHECK_MARK} ", use_color) |
75 | 69 | elif status == "FAILED" or status == "ROLLBACK_FAILED": |
76 | | - return ColorUtils.make_red("X ", use_color) |
| 70 | + return self.make_red("X ", use_color) |
77 | 71 | elif ( |
78 | 72 | status == "DELETED" |
79 | 73 | or status == "STOPPED" |
80 | 74 | or status == "ROLLBACK_SUCCESSFUL" |
81 | 75 | ): |
82 | | - return ColorUtils.make_yellow("— ", use_color) |
| 76 | + return self.make_yellow("— ", use_color) |
83 | 77 | else: |
84 | | - return ColorUtils.make_purple(f"{spinner_char} ", use_color) |
| 78 | + return self.make_purple(f"{spinner_char} ", use_color) |
0 commit comments