|
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 |
|
@@ -136,33 +139,42 @@ def __call__(self, event): # noqa: D102 |
136 | 139 | # runtime in seconds |
137 | 140 | duration_string = format_duration( |
138 | 141 | now - self._start_time, fixed_decimal_points=1) |
139 | | - blocks.append('[{duration_string}]'.format_map(locals())) |
| 142 | + blocks.append('[' + colorama.Fore.YELLOW + duration_string + |
| 143 | + colorama.Fore.RESET + ']') |
140 | 144 |
|
141 | 145 | # number of completed jobs / number of jobs |
142 | 146 | blocks.append( |
143 | | - '[%d/%d complete]' % |
144 | | - (len(self._ended), self._queued_count)) |
| 147 | + '[' + colorama.Style.BRIGHT + colorama.Fore.GREEN + |
| 148 | + str(len(self._ended)) + colorama.Style.RESET_ALL + '/' + |
| 149 | + colorama.Fore.GREEN + str(self._queued_count) + |
| 150 | + colorama.Fore.RESET + ' complete]') |
145 | 151 |
|
146 | 152 | # number of failed jobs if not zero |
147 | 153 | failed_jobs = [ |
148 | 154 | j for j, d in self._ended.items() |
149 | 155 | if d['rc'] and d['rc'] != SIGINT_RESULT] |
150 | 156 | if failed_jobs: |
151 | | - blocks.append('[%d failed]' % len(failed_jobs)) |
| 157 | + blocks.append('[' + colorama.Fore.RED + colorama.Style.BRIGHT + |
| 158 | + str(len(failed_jobs)) + colorama.Style.NORMAL + |
| 159 | + ' failed' + colorama.Fore.RESET + ']') |
152 | 160 |
|
153 | 161 | # number of ongoing jobs if greater one |
154 | 162 | if len(self._running) > 1: |
155 | | - blocks.append('[%d ongoing]' % len(self._running)) |
| 163 | + blocks.append('[' + colorama.Fore.GREEN + |
| 164 | + str(len(self._running)) + colorama.Fore.RESET + |
| 165 | + ' ongoing]') |
156 | 166 |
|
157 | 167 | # job identifier, label and time for ongoing jobs |
158 | 168 | for job, d in self._running.items(): |
159 | | - msg = job.task.context.pkg.name |
| 169 | + msg = (colorama.Fore.CYAN + job.task.context.pkg.name + |
| 170 | + colorama.Fore.RESET) |
160 | 171 | if 'progress' in d: |
161 | | - msg += ':%s' % ' '.join(d['progress']) |
| 172 | + msg += (':' + colorama.Fore.BLUE + ' '.join(d['progress']) + |
| 173 | + colorama.Fore.RESET) |
162 | 174 | duration_string = format_duration( |
163 | 175 | now - d['start_time'], fixed_decimal_points=1) |
164 | | - blocks.append( |
165 | | - '[{msg} - {duration_string}]'.format_map(locals())) |
| 176 | + blocks.append('[' + msg + ' - ' + colorama.Fore.YELLOW + |
| 177 | + duration_string + colorama.Fore.RESET + ']') |
166 | 178 |
|
167 | 179 | # determine blocks which fit into terminal width |
168 | 180 | max_width = shutil.get_terminal_size().columns |
|
0 commit comments