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.

Modules§

metrics
Pure Prometheus-text parsing + per-row aggregation for the live TUI.
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_metrics_recorder
Install the Prometheus recorder for a TUI session and return its render handle. When the config carries an observability.prometheus block the /metrics HTTP endpoint is preserved (recorder + listener, exactly what install_observability would have set up); otherwise a listener-less recorder is installed purely as the TUI’s data source. Idempotent: a second call returns the first call’s handle.
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.
setup_observability
Install the TUI session’s observability: the TUI owns the metrics recorder (keeping the /metrics endpoint when one is configured) so it can render the recorder’s output; the rest of the observability config (OTLP traces — the tracing level was already routed into the TUI log ring by run_main) installs as usual with the prometheus block taken out.