Skip to content

Commit 27f4c6c

Browse files
committed
Make output of colcon colorful
1 parent aa80ae5 commit 27f4c6c

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

colcon_core/event_handler/console_start_end.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import sys
55
import time
66

7+
import colorama
8+
79
from colcon_core.event.job import JobEnded
810
from colcon_core.event.job import JobStarted
911
from 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)

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ keywords = colcon
2727
[options]
2828
python_requires = >=3.6
2929
install_requires =
30+
colorama
3031
coloredlogs; sys_platform == 'win32'
3132
distlib
3233
EmPy<4

stdeb.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[colcon-core]
22
No-Python2:
3-
Depends3: python3-distlib, python3-empy (<4), python3-packaging, python3-pytest, python3-setuptools, python3 (>= 3.8) | python3-importlib-metadata
3+
Depends3: python3-colorama, python3-distlib, python3-empy (<4), python3-packaging, python3-pytest, python3-setuptools, python3 (>= 3.8) | python3-importlib-metadata
44
Recommends3: python3-pytest-cov
55
Suggests3: python3-pytest-repeat, python3-pytest-rerunfailures
66
Replaces3: colcon

0 commit comments

Comments
 (0)