Skip to content

Commit 90690fb

Browse files
Console: add status_ok/status_warn helpers (#318)
1 parent 01f9328 commit 90690fb

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/pystatsv1/console.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Console helpers.
2+
3+
PyStatsV1 aims to be beginner-friendly across Windows/macOS/Linux.
4+
Some Windows terminals still default to non-UTF-8 encodings (e.g., cp1252),
5+
so **runtime console output should stay ASCII-only by default**.
6+
7+
These helpers provide consistent, ASCII-safe status prefixes for scripts.
8+
"""
9+
10+
from __future__ import annotations
11+
12+
from typing import Final
13+
14+
OK_TAG: Final[str] = "[OK]"
15+
WARN_TAG: Final[str] = "[WARN]"
16+
FAIL_TAG: Final[str] = "NOT OK"
17+
18+
19+
def status_ok(message: str = "") -> str:
20+
"""Return an ASCII-safe OK status line.
21+
22+
Prefer using this in scripts instead of emoji markers, e.g.:
23+
24+
print(status_ok("Wrote outputs/..."))
25+
"""
26+
27+
if not message:
28+
return OK_TAG
29+
return f"{OK_TAG} {message}"
30+
31+
32+
def status_warn(message: str = "") -> str:
33+
"""Return an ASCII-safe WARN status line."""
34+
35+
if not message:
36+
return WARN_TAG
37+
return f"{WARN_TAG} {message}"
38+
39+
40+
def status_fail(message: str = "") -> str:
41+
"""Return an ASCII-safe FAIL status line."""
42+
43+
if not message:
44+
return FAIL_TAG
45+
return f"{FAIL_TAG} {message}"

tests/test_console_status.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from __future__ import annotations
2+
3+
4+
def test_status_helpers_are_ascii() -> None:
5+
from pystatsv1.console import status_fail, status_ok, status_warn
6+
7+
assert status_ok("hello").isascii()
8+
assert status_warn("hello").isascii()
9+
assert status_fail("hello").isascii()
10+
11+
12+
def test_status_helpers_prefixes() -> None:
13+
from pystatsv1.console import status_fail, status_ok, status_warn
14+
15+
assert status_ok("Done").startswith("[OK] ")
16+
assert status_warn("Heads up").startswith("[WARN] ")
17+
assert status_fail("Nope").startswith("NOT OK ")

0 commit comments

Comments
 (0)