Skip to content

Commit 82fe8a6

Browse files
committed
Make status output colorful
1 parent 5401d06 commit 82fe8a6

3 files changed

Lines changed: 23 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

@@ -126,33 +129,42 @@ def __call__(self, event): # noqa: D102
126129
# runtime in seconds
127130
duration_string = format_duration(
128131
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 + ']')
130134

131135
# number of completed jobs / number of jobs
132136
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]')
135141

136142
# number of failed jobs if not zero
137143
failed_jobs = [
138144
j for j, d in self._ended.items()
139145
if d['rc'] and d['rc'] != SIGINT_RESULT]
140146
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 + ']')
142150

143151
# number of ongoing jobs if greater one
144152
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]')
146156

147157
# job identifier, label and time for ongoing jobs
148158
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)
150161
if 'progress' in d:
151-
msg += ':%s' % ' '.join(d['progress'])
162+
msg += (':' + colorama.Fore.BLUE + ' '.join(d['progress']) +
163+
colorama.Fore.RESET)
152164
duration_string = format_duration(
153165
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 + ']')
156168

157169
# determine blocks which fit into terminal width
158170
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[colcon-notification]
22
No-Python2:
3-
Depends3: python3-colcon-core (>= 0.3.7), python3-notify2
3+
Depends3: python3-colcon-core (>= 0.3.7), python3-colorama, python3-notify2
44
Suite: bionic focal jammy stretch buster bullseye
55
X-Python3-Version: >= 3.5
66
Setup-Env-Vars: BUILD_DEBIAN_PACKAGE=1

0 commit comments

Comments
 (0)