blob: 1563b9235bbdf7025f70407beca4fb3bc8c4eb89 [file] [log] [blame]
Jeremy Johnsone2b5e872023-09-14 17:02:09 +01001"""Color printing module."""
2# Copyright (c) 2020-2023, ARM Limited.
3# SPDX-License-Identifier: Apache-2.0
4from enum import Enum
5from enum import unique
6
7color_printing = True
8
9
10@unique
11class LogColors(Enum):
12 """Shell escape sequence colors for logging."""
13
14 NONE = "\u001b[0m"
15 GREEN = "\u001b[32;1m"
16 RED = "\u001b[31;1m"
17 YELLOW = "\u001b[33;1m"
18 BOLD_WHITE = "\u001b[1m"
19
20
21def set_print_in_color(enabled):
22 """Set color printing to enabled or disabled."""
23 global color_printing
24 color_printing = enabled
25
26
27def print_color(color, msg):
28 """Print color status messages if enabled."""
29 global color_printing
30 if not color_printing:
31 print(msg)
32 else:
33 print("{}{}{}".format(color.value, msg, LogColors.NONE.value))