|
7 | 7 | import sys |
8 | 8 | import time |
9 | 9 |
|
| 10 | +import colorama |
| 11 | + |
10 | 12 | from colcon_core.event.job import JobEnded |
11 | 13 | from colcon_core.event.job import JobProgress |
12 | 14 | from colcon_core.event.job import JobQueued |
@@ -42,6 +44,7 @@ class StatusEventHandler(EventHandlerExtensionPoint): |
42 | 44 |
|
43 | 45 | def __init__(self): # noqa: D107 |
44 | 46 | super().__init__() |
| 47 | + colorama.init() |
45 | 48 | satisfies_version( |
46 | 49 | EventHandlerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') |
47 | 50 |
|
@@ -126,33 +129,42 @@ def __call__(self, event): # noqa: D102 |
126 | 129 | # runtime in seconds |
127 | 130 | duration_string = format_duration( |
128 | 131 | now - self._start_time, fixed_decimal_points=1) |
129 | | - blocks.append('[{duration_string}]'.format_map(locals())) |
| 132 | + blocks.append('[' + colorama.Fore.YELLOW + duration_string + |
| 133 | + colorama.Fore.RESET + ']') |
130 | 134 |
|
131 | 135 | # number of completed jobs / number of jobs |
132 | 136 | blocks.append( |
133 | | - '[%d/%d complete]' % |
134 | | - (len(self._ended), self._queued_count)) |
| 137 | + '[' + colorama.Style.BRIGHT + colorama.Fore.GREEN + |
| 138 | + str(len(self._ended)) + colorama.Style.RESET_ALL + '/' + |
| 139 | + colorama.Fore.GREEN + str(self._queued_count) + |
| 140 | + colorama.Fore.RESET + ' complete]') |
135 | 141 |
|
136 | 142 | # number of failed jobs if not zero |
137 | 143 | failed_jobs = [ |
138 | 144 | j for j, d in self._ended.items() |
139 | 145 | if d['rc'] and d['rc'] != SIGINT_RESULT] |
140 | 146 | if failed_jobs: |
141 | | - blocks.append('[%d failed]' % len(failed_jobs)) |
| 147 | + blocks.append('[' + colorama.Fore.RED + colorama.Style.BRIGHT + |
| 148 | + str(len(failed_jobs)) + colorama.Style.NORMAL + |
| 149 | + ' failed' + colorama.Fore.RESET + ']') |
142 | 150 |
|
143 | 151 | # number of ongoing jobs if greater one |
144 | 152 | if len(self._running) > 1: |
145 | | - blocks.append('[%d ongoing]' % len(self._running)) |
| 153 | + blocks.append('[' + colorama.Fore.GREEN + |
| 154 | + str(len(self._running)) + colorama.Fore.RESET + |
| 155 | + ' ongoing]') |
146 | 156 |
|
147 | 157 | # job identifier, label and time for ongoing jobs |
148 | 158 | for job, d in self._running.items(): |
149 | | - msg = job.task.context.pkg.name |
| 159 | + msg = (colorama.Fore.CYAN + job.task.context.pkg.name + |
| 160 | + colorama.Fore.RESET) |
150 | 161 | if 'progress' in d: |
151 | | - msg += ':%s' % ' '.join(d['progress']) |
| 162 | + msg += (':' + colorama.Fore.BLUE + ' '.join(d['progress']) + |
| 163 | + colorama.Fore.RESET) |
152 | 164 | duration_string = format_duration( |
153 | 165 | now - d['start_time'], fixed_decimal_points=1) |
154 | | - blocks.append( |
155 | | - '[{msg} - {duration_string}]'.format_map(locals())) |
| 166 | + blocks.append('[' + msg + ' - ' + colorama.Fore.YELLOW + |
| 167 | + duration_string + colorama.Fore.RESET + ']') |
156 | 168 |
|
157 | 169 | # determine blocks which fit into terminal width |
158 | 170 | max_width = shutil.get_terminal_size().columns |
|
0 commit comments