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 = {}
@@ -35,7 +38,10 @@ def __call__(self, event): # noqa: D102
3538
3639 if isinstance (data , JobStarted ):
3740 self ._start_times [data .identifier ] = time .monotonic ()
38- print (f'Starting >>> { data .identifier } ' , flush = True )
41+ msg = ('Starting ' + colorama .Fore .GREEN +
42+ colorama .Style .BRIGHT + '>>>' + colorama .Fore .CYAN +
43+ f' { data .identifier } ' + colorama .Style .RESET_ALL )
44+ print (msg , flush = True )
3945
4046 elif isinstance (data , TestFailure ):
4147 job = event [1 ]
@@ -46,19 +52,30 @@ def __call__(self, event): # noqa: D102
4652 time .monotonic () - self ._start_times [data .identifier ]
4753 duration_string = format_duration (duration )
4854 if not data .rc :
49- msg = f'Finished <<< { data .identifier } [{ duration_string } ]'
55+ msg = (colorama .Style .BRIGHT + colorama .Fore .BLACK +
56+ 'Finished ' + colorama .Fore .GREEN + '<<<'
57+ + colorama .Style .RESET_ALL + colorama .Fore .CYAN
58+ + f' { data .identifier } ' + colorama .Fore .RESET
59+ + ' [' + colorama .Fore .YELLOW +
60+ f'{ duration_string } ' + colorama .Fore .RESET + ']' )
5061 job = event [1 ]
5162 if job in self ._with_test_failures :
5263 msg += '\t [ with test failures ]'
5364 writable = sys .stdout
5465
5566 elif data .rc == SIGINT_RESULT :
56- msg = f'Aborted <<< { data .identifier } [{ duration_string } ]'
67+ msg = (colorama .Style .BRIGHT + colorama .Fore .RED +
68+ 'Aborted ' + colorama .Style .NORMAL + '<<<'
69+ + colorama .Fore .CYAN + f' { data .identifier } '
70+ + colorama .Fore .RESET )
5771 writable = sys .stdout
58-
5972 else :
60- msg = f'Failed <<< { data .identifier } ' \
61- f'[{ duration_string } , exited with code { data .rc } ]'
73+ msg = (colorama .Style .BRIGHT + colorama .Fore .RED +
74+ 'Failed ' + colorama .Style .NORMAL + '<<<' +
75+ colorama .Fore .CYAN + f' { data .identifier } ' +
76+ colorama .Fore .RESET + ' [' + colorama .Fore .RED +
77+ f'Exited with code { data .rc } ' +
78+ colorama .Fore .RESET + ']' )
6279 writable = sys .stderr
6380
6481 print (msg , file = writable , flush = True )
0 commit comments