Skip to main content

Module tui

Module tui 

Source
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, the lev setup wizard, and the markdown renderer).

Structs§

CrosstermEventSource
Production EventSource: reads real terminal input via crossterm. Uses injectable function pointers for poll and read so the two branches of poll_event can be exercised in unit tests without a real TTY. In production, construct via CrosstermEventSource::new. Wired into the real UIs only by the binary.

Traits§

EventSource
Abstracts “give me the next input event, or None if 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.
TerminalSetup
Abstracts terminal setup/teardown so a UI’s generic core can be tested with a ratatui::backend::TestBackend and no-op TTY operations. The real crossterm implementation (CrosstermSetup) lives in the binary, since it can only be exercised against a real terminal.