|
16 | 16 |
|
17 | 17 | class ColorShell: |
18 | 18 |
|
| 19 | + def _color(self, color, text): |
| 20 | + return f'{color}{text}{SHELL_COLOR_ENDC}' |
| 21 | + |
| 22 | + def red(self, text): |
| 23 | + return self._color(text, SHELL_COLOR_DANGER) |
| 24 | + |
| 25 | + def orange(self, text): |
| 26 | + return self._color(text, SHELL_COLOR_ALERT) |
| 27 | + |
| 28 | + def yellow(self, text): |
| 29 | + return self._color(text, SHELL_COLOR_WARNING) |
| 30 | + |
| 31 | + def blue(self, text): |
| 32 | + return self._color(text, SHELL_COLOR_INFO) |
| 33 | + |
| 34 | + def green(self, text): |
| 35 | + return self._color(text, SHELL_COLOR_SUCCESS) |
| 36 | + |
| 37 | + def lmn(self, text): |
| 38 | + return self._color(text, SHELL_COLOR_LINUXMUSTER) |
| 39 | + |
| 40 | + |
| 41 | +class PrintShell: |
| 42 | + |
| 43 | + def __init__(self): |
| 44 | + self.color_shell = ColorShell() |
| 45 | + self._color = self.color_shell._color |
| 46 | + |
| 47 | + def printsh(self, color, text, end="\n"): |
| 48 | + """ |
| 49 | + Method for not so common colors. But color should be a valid ANSI control sequence. |
| 50 | + """ |
| 51 | + |
| 52 | + print(self._color(color, text), end=end) |
| 53 | + |
19 | 54 | def danger(self, result, end="\n"): |
20 | | - print(f'{SHELL_COLOR_DANGER}{result}{SHELL_COLOR_ENDC}', end=end) |
| 55 | + self.printsh(SHELL_COLOR_DANGER, result, end=end) |
21 | 56 |
|
22 | 57 | def alert(self, result, end="\n"): |
23 | | - print(f'{SHELL_COLOR_ALERT}{result}{SHELL_COLOR_ENDC}', end=end) |
| 58 | + self.printsh(SHELL_COLOR_ALERT, result, end=end) |
24 | 59 |
|
25 | 60 | def warning(self, result, end="\n"): |
26 | | - print(f'{SHELL_COLOR_WARNING}{result}{SHELL_COLOR_ENDC}', end=end) |
| 61 | + self.printsh(SHELL_COLOR_WARNING, result, end=end) |
27 | 62 |
|
28 | 63 | def info(self, result, end="\n"): |
29 | | - print(f'{SHELL_COLOR_INFO}{result}{SHELL_COLOR_ENDC}', end=end) |
| 64 | + self.printsh(SHELL_COLOR_INFO, result, end=end) |
30 | 65 |
|
31 | 66 | def success(self, result, end="\n"): |
32 | | - print(f'{SHELL_COLOR_SUCCESS}{result}{SHELL_COLOR_ENDC}', end=end) |
| 67 | + self.printsh(SHELL_COLOR_SUCCESS, result, end=end) |
33 | 68 |
|
34 | 69 | def lmn(self, result, end="\n"): |
35 | | - print(f'{SHELL_COLOR_LINUXMUSTER}{result}{SHELL_COLOR_ENDC}', end=end) |
36 | | - |
37 | | - def printsh(self, text, color, end="\n"): |
38 | | - """ |
39 | | - Method for not so common colors. But color should be a valid ANSI control sequence |
40 | | - """ |
41 | | - |
| 70 | + self.printsh(SHELL_COLOR_LINUXMUSTER, result, end=end) |
42 | 71 |
|
43 | | - print(f'{color}{text}{SHELL_COLOR_ENDC}', end=end) |
44 | 72 |
|
45 | 73 | # Mostly copied from https://github.com/not-kennethreitz/blindspin |
46 | 74 | class Spinner(object): |
|
0 commit comments