Skip to main content

Module tui

Module tui 

Source
Expand description

vcon-server tui: a terminal UI for a running server (cargo feature tui, on by default).

It is a client of the server’s HTTP API with one API key, as any other client is: it opens no data directory, catalog or master key, so the server’s scopes, tenant bounds and audit log apply to everything it shows. It reads only: the key’s tenant’s vCons as the API lists them (uuid, version and times), one vCon’s masked view (?view=masked, no content), and a part of it when a reveal key asks for it (?reveal=<part>, recorded in the audit log).

The parts: state is the state machine, view draws a state, keys is the one table of bindings, and client is the API behind a trait. This module joins them to a real terminal.

Modules§

client
The server’s HTTP API as the terminal UI uses it: GET /key, GET /vcons, a vCon’s masked view (?view=masked) and its reveals (?reveal=<part>), with one bearer key over TLS. The requests are behind Api, so the UI is driven in tests without a network; the conversions a request makes (its path, and its answer to a value) are functions of their own.
keys
The key bindings: one table, read by the key reader, the footer and the help view, so what is shown is what is bound.
state
The terminal UI’s state machine: a state and an event give the next state and the requests to make. It draws nothing, reads no clock and calls no server, so every transition can be tested as a value.
view
Drawing: a state and a theme give a frame. It reads nothing but its arguments, so every screen is tested on ratatui’s TestBackend at the size the test chooses.

Traits§

Inputs
Where the terminal’s events come from: the keyboard in run, a script in tests.

Functions§

drive
The loop: applies every answer in inbox, draws, waits one tick for an event and applies it, until the state says quit. Each request the state asks for goes to dispatch, whose answer comes back through inbox; now is the clock. Returns the state at the end.
require_terminal
Whether the UI can start: it reads keys from standard input and draws on standard output, so each must be a terminal. input and output say whether they are.
run
Runs the UI on this process’s terminal until the user quits.
translate
What a terminal event asks of the state: a bound key’s action when the key goes down, or the new size. Releases, repeats of a release, the mouse, focus and paste are nothing.
with_terminal
Runs body with this process’s terminal taken for a UI (keys one at a time and not echoed, the alternate screen), and puts the terminal back when body returns and when it panics (through the hook ratatui::try_init installs, which runs before the panic’s message is written). Returns what body returned.