Skip to main content

Crate tern_sdk

Crate tern_sdk 

Source
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:

  1. wire: constants, typed messages both ways, the encoder (framing, chunking, blobs) and the decoder.
  2. input and keys: the streaming input parser that splits TSP out of the pty’s input, and the key decoder.
  3. ui: typed builders for every kind and prop, styled spans, and handlers mapping events to the program’s messages.
  4. reconcile: views diffed into frame ops with derived ids, exactly as Tern’s plugin worker does it.
  5. Session: the handshake, raw mode, surfaces, flow control, blobs, event routing, recording and a clean exit.
  6. [print], ask and plain: 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>] u keys 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, theme and motion events.
Options
How to connect.
PrintOptions
Options of [print].
Session
A connection to a terminal that speaks TSP. Dropping it closes it (surfaces, modes, tty).
Submission
A submitted form: the action event that submitted it.
Surface
A surface of a session, as Session::open returned it (only valid with that session; another session’s handle panics).
SurfaceOptions
How to open a surface.

Enums§

Answer
What ask got.
Error
What can go wrong talking TSP.
Input
What Session::next returns.

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 to update, and a view it returns is rendered in place.
plain
Renders a message-free view or builder as plain text cols columns wide (rules span it; text isn’t wrapped). Lines end with \n.
print
Shows view as static output that stays in the scrollback.