From 8effab0f840063881fe9e0355a500e025d73b9c2 Mon Sep 17 00:00:00 2001 From: Yossi O Date: Fri, 28 Jun 2019 17:47:11 +0300 Subject: [PATCH] Added colors to colcon output --- .../event_handler/console_start_end.py | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/colcon_core/event_handler/console_start_end.py b/colcon_core/event_handler/console_start_end.py index 8a8ffce9..6fe26567 100644 --- a/colcon_core/event_handler/console_start_end.py +++ b/colcon_core/event_handler/console_start_end.py @@ -12,6 +12,24 @@ from colcon_core.plugin_system import satisfies_version from colcon_core.subprocess import SIGINT_RESULT +class bcolors: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + FIN = '\x1b[1;30m' + FINBR = '\033[32m' + START = '\x1b[1;37m' + STARTBR = '\033[92m' + TIME = '\x1b[1;33m' + PKG_NAME = '\033[96m' + + + class ConsoleStartEndEventHandler(EventHandlerExtensionPoint): """ @@ -34,8 +52,8 @@ def __call__(self, event): # noqa: D102 data = event[0] if isinstance(data, JobStarted): - print( - 'Starting >>> {data.identifier}'.format_map(locals()), + msg_template=bcolors.START + 'Starting ' + bcolors.STARTBR+ '>>>' + bcolors.PKG_NAME + ' {data.identifier}' + bcolors.ENDC + print(msg_template.format_map(locals()), flush=True) self._start_times[data.identifier] = time.time() @@ -47,20 +65,20 @@ def __call__(self, event): # noqa: D102 if not data.rc: duration = time.time() - self._start_times[data.identifier] duration_string = format_duration(duration) - msg = 'Finished <<< {data.identifier} [{duration_string}]' \ - .format_map(locals()) + msg_template = bcolors.FIN + 'Finished '+ bcolors.FINBR + '<<<'+ bcolors.PKG_NAME + ' {data.identifier}' + bcolors.ENDC +' ['+bcolors.TIME+'{duration_string}'+bcolors.ENDC+']' + 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}'.format_map(locals()) + msg_template = bcolors.WARNING + 'Aborted ' + '<<<'+ bcolors.PKG_NAME + ' {data.identifier}' + bcolors.ENDC + msg = msg_template.format_map(locals()) writable = sys.stdout - else: - msg = 'Failed <<< {data.identifier}\t' \ - '[ Exited with code {data.rc} ]'.format_map(locals()) + msg_template = bcolors.FAIL + 'Failed ' + '<<<'+ bcolors.PKG_NAME + ' {data.identifier}' + bcolors.ENDC +' ['+bcolors.FAIL+'Exited with code {data.rc}'+bcolors.ENDC+']' + msg = msg_template.format_map(locals()) writable = sys.stderr print(msg, file=writable, flush=True)