44import sys
55import time
66
7+ import colorama
8+
79from colcon_core .event .job import JobEnded
810from colcon_core .event .job import JobStarted
911from colcon_core .event .test import TestFailure
@@ -25,6 +27,7 @@ class ConsoleStartEndEventHandler(EventHandlerExtensionPoint):
2527
2628 def __init__ (self ): # noqa: D107
2729 super ().__init__ ()
30+ colorama .init ()
2831 satisfies_version (
2932 EventHandlerExtensionPoint .EXTENSION_POINT_VERSION , '^1.0' )
3033 self ._start_times = {}
@@ -34,8 +37,10 @@ def __call__(self, event): # noqa: D102
3437 data = event [0 ]
3538
3639 if isinstance (data , JobStarted ):
37- print (
38- 'Starting >>> {data.identifier}' .format_map (locals ()),
40+ msg_template = ('Starting ' + colorama .Fore .GREEN +
41+ colorama .Style .BRIGHT + '>>>' + colorama .Fore .CYAN +
42+ ' {data.identifier}' + colorama .Style .RESET_ALL )
43+ print (msg_template .format_map (locals ()),
3944 flush = True )
4045 self ._start_times [data .identifier ] = time .monotonic ()
4146
@@ -48,22 +53,35 @@ def __call__(self, event): # noqa: D102
4853 time .monotonic () - self ._start_times [data .identifier ]
4954 duration_string = format_duration (duration )
5055 if not data .rc :
51- msg = 'Finished <<< {data.identifier} [{duration_string}]' \
52- .format_map (locals ())
56+ duration = time .time () - self ._start_times [data .identifier ]
57+ duration_string = format_duration (duration )
58+ msg_template = (colorama .Style .BRIGHT + colorama .Fore .BLACK +
59+ 'Finished ' + colorama .Fore .GREEN + '<<<'
60+ + colorama .Style .RESET_ALL + colorama .Fore .CYAN
61+ + ' {data.identifier}' + colorama .Fore .RESET
62+ + ' [' + colorama .Fore .YELLOW +
63+ '{duration_string}' + colorama .Fore .RESET + ']' )
64+ msg = msg_template .format_map (locals ())
5365 job = event [1 ]
5466 if job in self ._with_test_failures :
5567 msg += '\t [ with test failures ]'
5668 writable = sys .stdout
5769
5870 elif data .rc == SIGINT_RESULT :
59- msg = 'Aborted <<< {data.identifier} [{duration_string}]' \
60- .format_map (locals ())
71+ msg_template = (colorama .Style .BRIGHT + colorama .Fore .RED +
72+ 'Aborted ' + colorama .Style .NORMAL + '<<<'
73+ + colorama .Fore .CYAN + ' {data.identifier}'
74+ + colorama .Fore .RESET )
75+ msg = msg_template .format_map (locals ())
6176 writable = sys .stdout
62-
6377 else :
64- msg = 'Failed <<< {data.identifier} ' \
65- '[{duration_string}, exited with code {data.rc}]' \
66- .format_map (locals ())
78+ msg_template = (colorama .Style .BRIGHT + colorama .Fore .RED +
79+ 'Failed ' + colorama .Style .NORMAL + '<<<' +
80+ colorama .Fore .CYAN + ' {data.identifier}' +
81+ colorama .Fore .RESET + ' [' + colorama .Fore .RED +
82+ 'Exited with code {data.rc}' +
83+ colorama .Fore .RESET + ']' )
84+ msg = msg_template .format_map (locals ())
6785 writable = sys .stderr
6886
6987 print (msg , file = writable , flush = True )
0 commit comments