Expand description
Talk to Tern over the Tern Surface Protocol (TSP).
A program running in a terminal pane describes its UI as a tree of nodes; Tern lays it out, draws and animates it natively. Outside Tern the same program falls back to plain text. Six layers, each usable without the ones above it:
wire: constants, typed messages both ways, the encoder (framing, chunking, blobs) and the decoder.inputandkeys: the streaming input parser that splits TSP out of the pty’s input, and the key decoder.ui: typed builders for every kind and prop, styled spans, and handlers mapping events to the program’s messages.reconcile: views diffed into frame ops with derived ids, exactly as Tern’s plugin worker does it.Session: the handshake, raw mode, surfaces, flow control, blobs, event routing, recording and a clean exit.- [
print],askandplain: one-call helpers and the plain-text fallback.
Process-tty APIs (term::Tty, Session::connect, print and ask)
require Unix or Windows. The wire, input, node and reconcile layers
also build on wasm32-unknown-unknown.
§Example
use tern_sdk::{PrintOptions, ui, ui::View};
let view: View = View::new().main([ui::card().head("Deploy").status(ui::Status::Done).child(
ui::kv()
.item("service", "api-gateway")
.item("region", "eu-west-1"),
)]);
// A native card in Tern; plain text anywhere else.
tern_sdk::print(view, PrintOptions::new())?;Re-exports§
pub use keys::Key;pub use ui::Node;pub use ui::View;pub use wire::Event;pub use wire::Mode;pub use wire::Op;
Modules§
- input
- Layer 2a: the input parser. It splits TSP replies and events, and DA1 answers, out of the pty’s input and passes every other byte through as key bytes, exactly as they came.
- keys
- Layer 2b: the key decoder. It turns key bytes (what the input parser
passes through) into keys named as in Tern’s plugin API: legacy xterm
input, kitty
CSI <code>[;<mods>] ukeys and bracketed paste. - reconcile
- Layer 4: reconcile. A view diffed into frame ops with derived ids. Tern’s plugin worker uses this reconciler directly.
- term
- The terminal a session talks through.
- ui
- Layer 3: nodes. Typed builders for every kind (except
block, which is Tern’s own), every documented prop, the common props, styled spans and handlers that map events to the program’s messages. - wire
- Layer 1: the wire. Constants, the messages a program sends and receives, the encoder (framing, chunking, blobs) and the decoder of replies and events.
Macros§
- nodes
- Builds
Vec<Node<M>>from builders of different kinds. - spans
- Builds
Vec<Span>from strings and spans.
Structs§
- AskOptions
- Options of
ask. - Capabilities
- What the terminal draws and supports, kept current by
resize,themeandmotionevents. - Options
- How to connect.
- Print
Options - Options of [
print]. - Session
- A connection to a terminal that speaks TSP. Dropping it closes it (surfaces, modes, tty).
- Submission
- A submitted form: the
actionevent that submitted it. - Surface
- A surface of a session, as
Session::openreturned it (only valid with that session; another session’s handle panics). - Surface
Options - How to open a surface.
Enums§
- Answer
- What
askgot. - Error
- What can go wrong talking TSP.
- Input
- What
Session::nextreturns.
Functions§
- ask
- Asks one question: shows
view(a form) and returns its submission. - ask_
with ask, with the form’s handlers running while it waits: each message goes toupdate, and a view it returns is rendered in place.- plain
- Renders a message-free view or builder as plain text
colscolumns wide (rules span it; text isn’t wrapped). Lines end with\n. - Shows
viewas static output that stays in the scrollback.