Expand description
Seams shared by every Leviath terminal UI.
A ratatui app has exactly two pieces that cannot run under cargo test:
taking over the real terminal (raw mode + alternate screen + a
CrosstermBackend on real stdout) and blocking on real keyboard input.
TerminalSetup and EventSource abstract those two, so a UI’s whole
loop is unit-testable against a ratatui::backend::TestBackend and a
canned event list while the real crossterm bindings live in the
coverage-excluded lev binary.
This started as commands/dashboard-private code. It moved here when the
lev setup wizard became a second ratatui surface: both drive the same
CrosstermSetup from main.rs, share theme, and share the test doubles
below.
§Why the test doubles live here, not in each UI’s test module
cargo-llvm-cov reports generic functions per instantiation. A UI loop
generic over B: Backend that monomorphizes over two backend types gets two
region reports, and any arm exercised in only one of them shows as partially
covered. Keeping exactly one TestEventSource and one
TestBackendHarness for the whole crate means each loop monomorphizes
once, and both the success and the error arms of its ?s land inside that
single instantiation. Both doubles therefore carry an injectable-failure
switch rather than having an always-failing sibling type.
Modules§
- theme
- Color palette, glyph constants, and spinner frames shared by every Leviath
terminal UI (
lev dash, thelev setupwizard, and the markdown renderer).
Structs§
- Crossterm
Event Source - Production
EventSource: reads real terminal input via crossterm. Uses injectable function pointers forpollandreadso the two branches ofpoll_eventcan be exercised in unit tests without a real TTY. In production, construct viaCrosstermEventSource::open. Wired into the real UIs only by the binary.
Traits§
- Event
Source - Abstracts “give me the next input event, or
Noneif the poll timeout elapses” (i.e.crossterm::event::poll+event::read), so a UI’s main loop can be driven by canned events in tests instead of blocking on a real terminal. - Terminal
Setup - Abstracts terminal setup/teardown so a UI’s generic core can be tested with
a
ratatui::backend::TestBackendand no-op TTY operations. The real crossterm implementation (CrosstermSetup) lives in the binary, since it can only be exercised against a real terminal.