feat: Add shared status composition for truthful monitoring states (issue #78)
This commit is contained in:
+38
-19
@@ -52,6 +52,13 @@ from .status import (
|
||||
read_config,
|
||||
)
|
||||
from .monitoring_periods import get_open_period
|
||||
from .status_composition import (
|
||||
StatusState,
|
||||
StatusComposition,
|
||||
compose_status,
|
||||
render_status_tui,
|
||||
STATUS_POLL_INTERVAL_S,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -1111,22 +1118,23 @@ class FenrisTuiApp(App):
|
||||
# --- Service strip (§7.2 bottom) ---
|
||||
try:
|
||||
svc = _query_service_facts(conn, self._clock_now)
|
||||
boot = "enabled" if svc.get("boot_enabled") else "disabled"
|
||||
activity = "active" if svc.get("timer_active") else "inactive"
|
||||
collect = "ok" if svc.get("last_collect_ok") else "FAILED"
|
||||
freshness = svc.get("freshness", "unknown")
|
||||
self.query_one("#service-strip").update(
|
||||
"boot: %s · timer: %s · last collect: %s · freshness: %s · "
|
||||
"[dim]by Bongbetic[/dim]\n"
|
||||
"[bold]CONTINUITY[/bold] %s\n"
|
||||
"%s\n"
|
||||
"p pause · r resume · c collect · d disclosures"
|
||||
% (
|
||||
boot, activity, collect, freshness,
|
||||
monitoring_continuity(svc), svc.get("period", ""),
|
||||
)
|
||||
# Use shared status composition
|
||||
comp = compose_status(
|
||||
conn, svc, self._clock_now,
|
||||
store_fault=None,
|
||||
newer_schema=None,
|
||||
reduced_motion=False,
|
||||
)
|
||||
self._render_paused_banner(svc)
|
||||
# Render using the shared composition with TUI styling
|
||||
status_text = render_status_tui(comp)
|
||||
# Add TUI-only branding and actions
|
||||
self.query_one("#service-strip").update(
|
||||
"%s\n"
|
||||
"[dim]by Bongbetic[/dim]\n"
|
||||
"p pause · r resume · c collect · d disclosures"
|
||||
% status_text
|
||||
)
|
||||
self._render_paused_banner(comp)
|
||||
except Exception:
|
||||
self._hide_paused_banner()
|
||||
self.query_one("#service-strip").update(
|
||||
@@ -1135,13 +1143,24 @@ class FenrisTuiApp(App):
|
||||
"p pause · r resume · c collect · d disclosures"
|
||||
)
|
||||
|
||||
def _render_paused_banner(self, service: Dict[str, Any]) -> None:
|
||||
"""Show the high-contrast Deliberate disable block only when sanctioned."""
|
||||
def _render_paused_banner(self, comp) -> None:
|
||||
"""Show the high-contrast Deliberate disable block only when sanctioned.
|
||||
|
||||
Accepts either a StatusComposition or a dict for backward compatibility.
|
||||
"""
|
||||
banner = self.query_one("#paused-banner")
|
||||
if service.get("deliberately_paused"):
|
||||
# Support both StatusComposition and legacy dict
|
||||
if hasattr(comp, 'deliberately_paused'):
|
||||
is_paused = comp.deliberately_paused
|
||||
paused_lines = comp.paused_lines
|
||||
else:
|
||||
is_paused = comp.get("deliberately_paused", False)
|
||||
paused_lines = deliberate_pause_lines() if is_paused else []
|
||||
|
||||
if is_paused and paused_lines:
|
||||
banner.update(
|
||||
"[bold black on red]%s[/bold black on red]\n%s"
|
||||
% tuple(deliberate_pause_lines())
|
||||
% tuple(paused_lines)
|
||||
)
|
||||
banner.styles.display = "block"
|
||||
main_grid = self.query_one("#main-grid")
|
||||
|
||||
Reference in New Issue
Block a user