nmbrs_tui/lib.rs
1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! # nmbrs-tui
5//!
6//! Contract & axioms: [SRD 59](../../docs/SRD/59_tui_contract.md).
7//!
8//! Terminal UI for nmbrs, built on [ratatui]. Provides a live
9//! dashboard showing the scenario tree, per-phase progress and
10//! detail blocks, throughput sparklines, latency percentile
11//! histograms, an optional log panel, and a help overlay.
12//!
13//! ## Architecture
14//!
15//! - [`state::RunState`] — shared state between the executor
16//! thread and the render thread. Holds the canonical
17//! `SceneTree` (parent / children / status), the
18//! side-mapped `PhaseSummary` per node, active-phase live
19//! counters, log ring buffer, ops-history sparkline data,
20//! etc.
21//! - [`app::App`] — owns the render loop. Reads `RunState` at
22//! the tick rate (default 4 Hz) and produces a frame.
23//! Handles keyboard input (LOD cycle, log toggle, pause,
24//! help, control-edit prompt).
25//! - [`reporter`] — a `nmbrs_metrics::scheduler::Reporter`
26//! implementation that observers register so per-tick
27//! `MetricSet` snapshots flow into `RunState`'s sparkline /
28//! percentile histories.
29//! - `widgets` — small custom widgets where ratatui's
30//! built-ins fall short.
31//!
32//! Lifecycle: `nmbrs` builds a [`run_state_actor::RunStateHandle`]
33//! (the actor owns a private `RunState` and publishes immutable
34//! `Arc<RunState>` snapshots via `arc_swap::ArcSwap`), hands the
35//! handle to the runner-side executor via
36//! [`observer::TuiObserver`] and to the TUI thread, and spawns
37//! the TUI on a dedicated `std::thread` (not tokio — the TUI
38//! never blocks the async runtime). Observers and the TUI both
39//! mutate state by sending typed [`run_state_actor::RunStateCmd`]
40//! messages into the actor's inbox; nothing ever takes a write
41//! lock on shared state. See SRD-02 §"Display and Diagnostic
42//! Decoupling".
43//!
44//! ## See also
45//!
46//! - SRD 62 (`docs/SRD/62_tui_layout.md`) — layout, LOD
47//! cycle, phase status glyphs, spinner cadence, "scenario
48//! done?" semantics.
49//! - SRD 18b — scene tree (the canonical structure
50//! `RunState.tree` mirrors).
51//!
52//! [ratatui]: https://crates.io/crates/ratatui
53
54pub mod app;
55pub mod display_sink;
56pub mod formatted_line_sink;
57pub(crate) mod frame_broker;
58pub mod inspector_repl;
59pub mod inspector_server;
60pub mod key_watcher;
61pub mod log_only_observer;
62pub mod log_only_sink;
63pub mod observer;
64pub(crate) mod prompt_state;
65pub(crate) mod readout_panel;
66pub(crate) mod readout_sink;
67pub mod repl_state;
68pub mod reporter;
69pub mod run_state_actor;
70pub mod sink_supervisor;
71pub mod state;
72pub mod status_fold;
73pub(crate) mod tui_sink;
74pub(crate) mod widgets;