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,33 @@ 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+ msg_template = (colorama .Style .BRIGHT + colorama .Fore .BLACK +
57+ 'Finished ' + colorama .Fore .GREEN + '<<<'
58+ + colorama .Style .RESET_ALL + colorama .Fore .CYAN
59+ + ' {data.identifier}' + colorama .Fore .RESET
60+ + ' [' + colorama .Fore .YELLOW +
61+ '{duration_string}' + colorama .Fore .RESET + ']' )
62+ msg = msg_template .format_map (locals ())
5363 job = event [1 ]
5464 if job in self ._with_test_failures :
5565 msg += '\t [ with test failures ]'
5666 writable = sys .stdout
5767
5868 elif data .rc == SIGINT_RESULT :
59- msg = 'Aborted <<< {data.identifier} [{duration_string}]' \
60- .format_map (locals ())
69+ msg_template = (colorama .Style .BRIGHT + colorama .Fore .RED +
70+ 'Aborted ' + colorama .Style .NORMAL + '<<<'
71+ + colorama .Fore .CYAN + ' {data.identifier}'
72+ + colorama .Fore .RESET )
73+ msg = msg_template .format_map (locals ())
6174 writable = sys .stdout
62-
6375 else :
64- msg = 'Failed <<< {data.identifier} ' \
65- '[{duration_string}, exited with code {data.rc}]' \
66- .format_map (locals ())
76+ msg_template = (colorama .Style .BRIGHT + colorama .Fore .RED +
77+ 'Failed ' + colorama .Style .NORMAL + '<<<' +
78+ colorama .Fore .CYAN + ' {data.identifier}' +
79+ colorama .Fore .RESET + ' [' + colorama .Fore .RED +
80+ 'Exited with code {data.rc}' +
81+ colorama .Fore .RESET + ']' )
82+ msg = msg_template .format_map (locals ())
6783 writable = sys .stderr
6884
6985 print (msg , file = writable , flush = True )
0 commit comments