Skip to content

Commit e9a163c

Browse files
committed
Make status output colorful
1 parent 57845bb commit e9a163c

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

colcon_notification/event_handler/status.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import sys
88
import time
99

10+
import colorama
11+
1012
from colcon_core.event.job import JobEnded
1113
from colcon_core.event.job import JobProgress
1214
from colcon_core.event.job import JobQueued
@@ -42,6 +44,7 @@ class StatusEventHandler(EventHandlerExtensionPoint):
4244

4345
def __init__(self): # noqa: D107
4446
super().__init__()
47+
colorama.init()
4548
satisfies_version(
4649
EventHandlerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')
4750

@@ -136,33 +139,42 @@ def __call__(self, event): # noqa: D102
136139
# runtime in seconds
137140
duration_string = format_duration(
138141
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 + ']')
140144

141145
# number of completed jobs / number of jobs
142146
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]')
145151

146152
# number of failed jobs if not zero
147153
failed_jobs = [
148154
j for j, d in self._ended.items()
149155
if d['rc'] and d['rc'] != SIGINT_RESULT]
150156
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 + ']')
152160

153161
# number of ongoing jobs if greater one
154162
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]')
156166

157167
# job identifier, label and time for ongoing jobs
158168
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)
160171
if 'progress' in d:
161-
msg += ':%s' % ' '.join(d['progress'])
172+
msg += (':' + colorama.Fore.BLUE + ' '.join(d['progress']) +
173+
colorama.Fore.RESET)
162174
duration_string = format_duration(
163175
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 + ']')
166178

167179
# determine blocks which fit into terminal width
168180
max_width = shutil.get_terminal_size().columns

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ keywords = colcon
2727
[options]
2828
install_requires =
2929
colcon-core>=0.3.7
30+
colorama
3031
notify2; sys_platform == 'linux'
3132
pywin32; sys_platform == 'win32'
3233
packages = find:

stdeb.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[colcon-notification]
22
No-Python2:
3-
Build-Depends: python3-setuptools (>= 53.1.0)
43
Depends3: python3-colcon-core (>= 0.3.7), python3-notify2
54
Suite: bionic focal jammy stretch buster bullseye
65
X-Python3-Version: >= 3.5

0 commit comments

Comments
 (0)