Coverage for src/secchi/ui/widgets/bar.py: 45%
11 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-04 22:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-08-04 22:15 +0000
1"""Horizontal bar rendering — reused for adoption %, health scores, install %."""
3from __future__ import annotations
5from secchi.ui import palette
7_FULL = "▅"
8_EMPTY = "░"
11def render_bar(
12 fraction: float,
13 width: int = 16,
14 color: str = palette.PROGRESS_FG,
15 *,
16 filled_char: str = _FULL,
17 empty_char: str = _EMPTY,
18) -> str:
19 """Return a Rich-markup horizontal bar for `fraction` (0.0-1.0).
21 `color` must be a literal Rich color name (not a Textual CSS variable),
22 since this string is fed to Static.update()/Text markup, not the stylesheet.
23 """
24 fraction = max(0.0, min(1.0, fraction))
25 filled = round(fraction * width)
26 bar = filled_char * filled + empty_char * (width - filled)
27 if filled < width:
28 return (
29 f"[{color}]{filled_char * filled}[/]"
30 f"[{palette.PROGRESS_BG}]{empty_char * (width - filled)}[/]"
31 )
32 return f"[{color}]{bar}[/]"