diff options
Diffstat (limited to 'verif/checker/color_print.py')
-rw-r--r-- | verif/checker/color_print.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/verif/checker/color_print.py b/verif/checker/color_print.py new file mode 100644 index 0000000..1563b92 --- /dev/null +++ b/verif/checker/color_print.py @@ -0,0 +1,33 @@ +"""Color printing module.""" +# Copyright (c) 2020-2023, ARM Limited. +# SPDX-License-Identifier: Apache-2.0 +from enum import Enum +from enum import unique + +color_printing = True + + +@unique +class LogColors(Enum): + """Shell escape sequence colors for logging.""" + + NONE = "\u001b[0m" + GREEN = "\u001b[32;1m" + RED = "\u001b[31;1m" + YELLOW = "\u001b[33;1m" + BOLD_WHITE = "\u001b[1m" + + +def set_print_in_color(enabled): + """Set color printing to enabled or disabled.""" + global color_printing + color_printing = enabled + + +def print_color(color, msg): + """Print color status messages if enabled.""" + global color_printing + if not color_printing: + print(msg) + else: + print("{}{}{}".format(color.value, msg, LogColors.NONE.value)) |