Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorize colcon output #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions colcon_core/event_handler/console_start_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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()

Expand All @@ -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)