diff --git a/colcon_core/event_handler/console_start_end.py b/colcon_core/event_handler/console_start_end.py index a4370d08..b0443c8f 100644 --- a/colcon_core/event_handler/console_start_end.py +++ b/colcon_core/event_handler/console_start_end.py @@ -4,6 +4,8 @@ import sys import time +import colorama + from colcon_core.event.job import JobEnded from colcon_core.event.job import JobStarted from colcon_core.event.test import TestFailure @@ -25,6 +27,7 @@ class ConsoleStartEndEventHandler(EventHandlerExtensionPoint): def __init__(self): # noqa: D107 super().__init__() + colorama.init() satisfies_version( EventHandlerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') self._start_times = {} @@ -34,8 +37,10 @@ def __call__(self, event): # noqa: D102 data = event[0] if isinstance(data, JobStarted): - print( - 'Starting >>> {data.identifier}'.format_map(locals()), + msg_template = ('Starting ' + colorama.Fore.GREEN + + colorama.Style.BRIGHT + '>>>' + colorama.Fore.CYAN + + ' {data.identifier}' + colorama.Style.RESET_ALL) + print(msg_template.format_map(locals()), flush=True) self._start_times[data.identifier] = time.monotonic() @@ -48,22 +53,35 @@ def __call__(self, event): # noqa: D102 time.monotonic() - self._start_times[data.identifier] duration_string = format_duration(duration) if not data.rc: - msg = 'Finished <<< {data.identifier} [{duration_string}]' \ - .format_map(locals()) + duration = time.time() - self._start_times[data.identifier] + duration_string = format_duration(duration) + msg_template = (colorama.Style.BRIGHT + colorama.Fore.BLACK + + 'Finished ' + colorama.Fore.GREEN + '<<<' + + colorama.Style.RESET_ALL + colorama.Fore.CYAN + + ' {data.identifier}' + colorama.Fore.RESET + + ' [' + colorama.Fore.YELLOW + + '{duration_string}' + colorama.Fore.RESET + ']') + msg = msg_template.format_map(locals()) job = event[1] if job in self._with_test_failures: msg += '\t[ with test failures ]' writable = sys.stdout elif data.rc == SIGINT_RESULT: - msg = 'Aborted <<< {data.identifier} [{duration_string}]' \ - .format_map(locals()) + msg_template = (colorama.Style.BRIGHT + colorama.Fore.RED + + 'Aborted ' + colorama.Style.NORMAL + '<<<' + + colorama.Fore.CYAN + ' {data.identifier}' + + colorama.Fore.RESET) + msg = msg_template.format_map(locals()) writable = sys.stdout - else: - msg = 'Failed <<< {data.identifier} ' \ - '[{duration_string}, exited with code {data.rc}]' \ - .format_map(locals()) + msg_template = (colorama.Style.BRIGHT + colorama.Fore.RED + + 'Failed ' + colorama.Style.NORMAL + '<<<' + + colorama.Fore.CYAN + ' {data.identifier}' + + colorama.Fore.RESET + ' [' + colorama.Fore.RED + + 'Exited with code {data.rc}' + + colorama.Fore.RESET + ']') + msg = msg_template.format_map(locals()) writable = sys.stderr print(msg, file=writable, flush=True) diff --git a/setup.cfg b/setup.cfg index 41514513..652d2ea7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,6 +27,7 @@ keywords = colcon [options] python_requires = >=3.5 install_requires = + colorama coloredlogs; sys_platform == 'win32' distlib EmPy diff --git a/stdeb.cfg b/stdeb.cfg index a3f58f84..e0796288 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -1,5 +1,5 @@ [colcon-core] No-Python2: -Depends3: python3-distlib, python3-empy, python3-pytest, python3-pytest-cov, python3-setuptools +Depends3: python3-colorama, python3-distlib, python3-empy, python3-pytest, python3-pytest-cov, python3-setuptools Suite: bionic focal jammy stretch buster bullseye X-Python3-Version: >= 3.5