Skip to content

Commit

Permalink
Make summary colorful
Browse files Browse the repository at this point in the history
  • Loading branch information
timonegk committed Oct 30, 2023
1 parent bd1ec9a commit 2ea4e86
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
38 changes: 23 additions & 15 deletions colcon_output/event_handler/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import time

import colorama

from colcon_core.event.job import JobEnded
from colcon_core.event.job import JobQueued
from colcon_core.event.output import StderrLine
Expand Down Expand Up @@ -32,6 +34,7 @@ class SummaryHandler(EventHandlerExtensionPoint):

def __init__(self): # noqa: D107
super().__init__()
colorama.init()
satisfies_version(
EventHandlerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')
self._queued = set()
Expand Down Expand Up @@ -73,38 +76,43 @@ def _print_summary(self):

count, job_type, _ = _msg_arguments(
self._ended - self._interrupted - self._failed)
print('Summary: {count} {job_type} finished '
'[{duration_string}]'.format_map(locals()))
print(colorama.Fore.YELLOW + colorama.Style.BRIGHT + 'Summary: ' +
colorama.Fore.RESET + str(count) + colorama.Style.NORMAL + ' ' +
job_type + ' finished [' + colorama.Fore.YELLOW +
duration_string + colorama.Fore.RESET + ']')

if self._failed:
count, job_type, names = _msg_arguments(self._failed)
print(' {count} {job_type} failed: {names}'
.format_map(locals()))
print(colorama.Fore.RED +
' {count} {job_type} failed: '.format_map(locals()) +
colorama.Style.RESET_ALL + names)

if self._interrupted:
count, job_type, names = _msg_arguments(self._interrupted)
print(' {count} {job_type} aborted: {names}'
.format_map(locals()))
print(colorama.Fore.RED +
' {count} {job_type} aborted: '.format_map(locals()) +
colorama.Style.RESET_ALL + names)

if self._with_stderr:
count, job_type, names = _msg_arguments(self._with_stderr)
print(
' {count} {job_type} had stderr output: {names}'
.format_map(locals()))
print(colorama.Fore.YELLOW +
' {count} {job_type} had stderr output: '
.format_map(locals()) +
colorama.Style.RESET_ALL + names)

if self._with_test_failures:
count, job_type, names = _msg_arguments(
self._with_test_failures)
print(
' {count} {job_type} had test failures: {names}'
.format_map(locals()))
print(colorama.Fore.RED +
' {count} {job_type} had test failures: '
.format_map(locals()) +
colorama.Style.RESET_ALL + names)

if len(self._queued) > len(self._ended):
count = len(self._queued - self._ended)
job_type = get_job_type_word_form(count)
print(
' {count} {job_type} not processed'
.format_map(locals()))
print(colorama.Fore.BLACK + ' {count} {job_type} not processed'
.format_map(locals()) + colorama.Style.RESET_ALL)


def _msg_arguments(jobs):
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ keywords = colcon
python_requires = >=3.6
install_requires =
colcon-core>=0.3.8
colorama
packages = find:
zip_safe = true

Expand Down
2 changes: 1 addition & 1 deletion stdeb.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[colcon-output]
No-Python2:
Depends3: python3-colcon-core (>= 0.3.8)
Depends3: python3-colcon-core (>= 0.3.8), python3-colorama
Suite: focal jammy bullseye bookworm
X-Python3-Version: >= 3.6

0 comments on commit 2ea4e86

Please sign in to comment.