4
4
import sys
5
5
import time
6
6
7
+ import colorama
8
+
7
9
from colcon_core .event .job import JobEnded
8
10
from colcon_core .event .job import JobStarted
9
11
from colcon_core .event .test import TestFailure
@@ -25,6 +27,7 @@ class ConsoleStartEndEventHandler(EventHandlerExtensionPoint):
25
27
26
28
def __init__ (self ): # noqa: D107
27
29
super ().__init__ ()
30
+ colorama .init ()
28
31
satisfies_version (
29
32
EventHandlerExtensionPoint .EXTENSION_POINT_VERSION , '^1.0' )
30
33
self ._start_times = {}
@@ -35,7 +38,10 @@ def __call__(self, event): # noqa: D102
35
38
36
39
if isinstance (data , JobStarted ):
37
40
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 )
39
45
40
46
elif isinstance (data , TestFailure ):
41
47
job = event [1 ]
@@ -46,19 +52,30 @@ def __call__(self, event): # noqa: D102
46
52
time .monotonic () - self ._start_times [data .identifier ]
47
53
duration_string = format_duration (duration )
48
54
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 + ']' )
50
61
job = event [1 ]
51
62
if job in self ._with_test_failures :
52
63
msg += '\t [ with test failures ]'
53
64
writable = sys .stdout
54
65
55
66
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 )
57
71
writable = sys .stdout
58
-
59
72
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 + ']' )
62
79
writable = sys .stderr
63
80
64
81
print (msg , file = writable , flush = True )
0 commit comments