Skip to main content

Module tui

Module tui 

Source
Available on crate feature cli-tui only.
Expand description

Live terminal UI for faucet run --tui (#203, cli-tui feature).

The pipeline is untouched: it emits the same metrics series it always does, and the TUI samples the in-process Prometheus recorder’s rendered text a few times per second (read-only — zero hot-path impact) and draws a full-screen ratatui view: per-invocation throughput, errors, DLQ counts, bookmark age, and a live log pane. q (or Ctrl-C, which raw mode delivers as a key event) cancels cooperatively via the executor’s CancellationToken — in-flight invocations stop at their next page boundary and flush their sinks.

Log handling: the normal stdout subscriber would corrupt the alternate screen, so when a TUI session is detected at startup (--tui on a real TTY), run_main routes the fmt subscriber into an in-memory ring (log_buffer) that the TUI renders as its log pane. Lines are redacted at capture with the same registry the stdout writer uses. On a non-TTY (CI, pipes) the flag degrades to a plain run with a one-line notice.

Re-exports§

pub use crate::livemetrics as metrics;
pub use crate::livemetrics::install_metrics_recorder;
pub use crate::livemetrics::setup_observability;

Modules§

view
Rendering for the live TUI. The ratatui draw call is thin; everything that decides what to show (formatting, column selection under narrow widths, status labels) is a pure function with unit tests.

Structs§

LogBuffer
Ring-buffered log lines shared between the tracing subscriber (writer side, installed in run_main) and the TUI (render side).
LogBufferWriter
Line-splitting io::Write adapter for the tracing subscriber.

Traits§

CancelEvents
Source of user cancel requests — abstracted from crossterm so drive_loop is testable against a scripted sequence.

Functions§

drive
Drive the run future under the full-screen TUI. Returns the run’s result after the terminal is restored. cancel is the token wired into ExecuteOptions.cancel; q / Ctrl-C trigger it.
drive_loop
The render/cancel loop behind drive, generic over the terminal backend and the event source so it runs headless under test.
flush_logs_to_stderr
Flush the tail of the buffered log ring to stderr — called after terminal restore when the run failed, so the operator keeps the context that was on screen.
install_tui_tracing
Install the ring-buffered tracing subscriber for a TUI session. Called by run_main instead of the stdout subscriber, before any log line is emitted. Returns the buffer for the render loop.
is_tui_session
--tui was passed and stdout is a real terminal — the full-screen UI applies. On a non-TTY the caller degrades to a plain run.
log_buffer
The TUI log ring, if run_main installed one this process.