From 0b9b0c21645dee112a4ce257307ac2bcb9c7f2c9 Mon Sep 17 00:00:00 2001 From: Marco D'Aleo Date: Fri, 2 Oct 2026 14:49:19 +0100 Subject: [PATCH] Add bold cyan colour --- src/schedls/output.py | 4 +++- tests/unit/test_output.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/schedls/output.py b/src/schedls/output.py index 6f244c4..05313a1 100644 --- a/src/schedls/output.py +++ b/src/schedls/output.py @@ -34,6 +34,7 @@ _COLORS = { "red": "\033[31m", "green": "\033[32m", "yellow": "\033[33m", + "cyan": "\033[36m", } @@ -103,7 +104,8 @@ class Output: return width = max(len(key) for key, _ in pairs) for key, value in pairs: - self.line(f"{key.ljust(width)} {value}".rstrip()) + label = self.style(key.ljust(width), "bold", "cyan") + self.line(f"{label} {value}".rstrip()) def job_datetime(self, value: datetime | None) -> str | None: if value is None: diff --git a/tests/unit/test_output.py b/tests/unit/test_output.py index 644ab88..e59430b 100644 --- a/tests/unit/test_output.py +++ b/tests/unit/test_output.py @@ -18,6 +18,11 @@ from schedls.models import ( from schedls.output import Output, job_to_dict, jobs_document, sanitize_text +class _TTYStream(io.StringIO): + def isatty(self) -> bool: + return True + + def _systemd_job() -> ScheduledJob: return ScheduledJob( name="backup", @@ -80,12 +85,32 @@ def test_output_table_and_key_values() -> None: stream = io.StringIO() output = Output(json_mode=False, color="never", stdout=stream) output.table(["NAME", "BACKEND"], [["backup", "systemd"], ["cleanup", "cron"]]) + output.key_values([("Status", "active")]) text = stream.getvalue() assert "NAME" in text assert "backup" in text assert "\x1b" not in text +def test_key_values_colour_labels_but_not_values() -> None: + stream = io.StringIO() + output = Output(color="always", stdout=stream) + + output.key_values([("S", "active"), ("Status", "waiting")]) + + assert stream.getvalue() == ("\033[1m\033[36mS \033[0m active\n\033[1m\033[36mStatus\033[0m waiting\n") + + +def test_key_values_honours_no_color(monkeypatch) -> None: + monkeypatch.setenv("NO_COLOR", "1") + stream = _TTYStream() + output = Output(color="auto", stdout=stream) + + output.key_values([("Status", "active")]) + + assert "\x1b" not in stream.getvalue() + + def test_output_json_mode() -> None: stream = io.StringIO() output = Output(json_mode=True, color="never", stdout=stream)