|
12 | 12 | NO_COLOR_VARIABLE_NAME = 'KNACK_NO_COLOR' |
13 | 13 |
|
14 | 14 | # Override these values to customize the status message. |
15 | | -# The message should contain a placeholder indicating the subject (like 'This command group', 'Commend group xxx'). |
| 15 | +# The message should contain a placeholder indicating the subject (like 'This command group', 'Command group xxx'). |
16 | 16 | # (A dict is used to avoid the "from A import B" pitfall that creates a copy of the imported B.) |
17 | 17 | status_tag_messages = { |
18 | 18 | 'preview': "{} is in preview. It may be changed/removed in a future release.", |
19 | 19 | 'experimental': "{} is experimental and under development." |
20 | 20 | } |
21 | 21 |
|
| 22 | +# https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences |
| 23 | +color_map = { |
| 24 | + 'reset': '\x1b[0m', # Default |
| 25 | + 'preview': '\x1b[36m', # Foreground Cyan |
| 26 | + 'experimental': '\x1b[36m', # Foreground Cyan |
| 27 | + 'deprecation': '\x1b[33m', # Foreground Yellow |
| 28 | + 'critical': '\x1b[41m', # Background Red |
| 29 | + 'error': '\x1b[91m', # Bright Foreground Red |
| 30 | + 'warning': '\x1b[33m', # Foreground Yellow |
| 31 | + 'info': '\x1b[32m', # Foreground Green |
| 32 | + 'debug': '\x1b[36m', # Foreground Cyan |
| 33 | +} |
| 34 | + |
22 | 35 |
|
23 | 36 | class CommandResultItem(object): # pylint: disable=too-few-public-methods |
24 | 37 | def __init__(self, result, table_transformer=None, is_query_active=False, |
@@ -48,18 +61,16 @@ def __init__(self, obj): |
48 | 61 | class ColorizedString(object): |
49 | 62 |
|
50 | 63 | def __init__(self, message, color): |
51 | | - import colorama |
52 | 64 | self._message = message |
53 | | - self._color = getattr(colorama.Fore, color.upper(), None) |
| 65 | + self._color = color |
54 | 66 |
|
55 | 67 | def __len__(self): |
56 | 68 | return len(self._message) |
57 | 69 |
|
58 | 70 | def __str__(self): |
59 | | - import colorama |
60 | 71 | if not self._color: |
61 | 72 | return self._message |
62 | | - return self._color + self._message + colorama.Fore.RESET |
| 73 | + return self._color + self._message + color_map['reset'] |
63 | 74 |
|
64 | 75 |
|
65 | 76 | class StatusTag(object): |
|
0 commit comments