Add bold cyan colour
This commit is contained in:
2 files changed
+28
-1
No files matched your search
@@ -34,6 +34,7 @@ _COLORS = {
|
|||||||
"red": "\033[31m",
|
"red": "\033[31m",
|
||||||
"green": "\033[32m",
|
"green": "\033[32m",
|
||||||
"yellow": "\033[33m",
|
"yellow": "\033[33m",
|
||||||
|
"cyan": "\033[36m",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +104,8 @@ class Output:
|
|||||||
return
|
return
|
||||||
width = max(len(key) for key, _ in pairs)
|
width = max(len(key) for key, _ in pairs)
|
||||||
for key, value 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:
|
def job_datetime(self, value: datetime | None) -> str | None:
|
||||||
if value is None:
|
if value is None:
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ from schedls.models import (
|
|||||||
from schedls.output import Output, job_to_dict, jobs_document, sanitize_text
|
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:
|
def _systemd_job() -> ScheduledJob:
|
||||||
return ScheduledJob(
|
return ScheduledJob(
|
||||||
name="backup",
|
name="backup",
|
||||||
@@ -80,12 +85,32 @@ def test_output_table_and_key_values() -> None:
|
|||||||
stream = io.StringIO()
|
stream = io.StringIO()
|
||||||
output = Output(json_mode=False, color="never", stdout=stream)
|
output = Output(json_mode=False, color="never", stdout=stream)
|
||||||
output.table(["NAME", "BACKEND"], [["backup", "systemd"], ["cleanup", "cron"]])
|
output.table(["NAME", "BACKEND"], [["backup", "systemd"], ["cleanup", "cron"]])
|
||||||
|
output.key_values([("Status", "active")])
|
||||||
text = stream.getvalue()
|
text = stream.getvalue()
|
||||||
assert "NAME" in text
|
assert "NAME" in text
|
||||||
assert "backup" in text
|
assert "backup" in text
|
||||||
assert "\x1b" not 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:
|
def test_output_json_mode() -> None:
|
||||||
stream = io.StringIO()
|
stream = io.StringIO()
|
||||||
output = Output(json_mode=True, color="never", stdout=stream)
|
output = Output(json_mode=True, color="never", stdout=stream)
|
||||||
|
|||||||
Reference in new issue
Block a user