API Reference Terminalwire v#0.1.0

Copy Markdown View Source

Modules

Terminalwire v2 server for Elixir.

A small command router so your CLI reads like the commands themselves — public functions become commands, their parameters become arguments, and @desc becomes help. It's the Elixir analog of Ruby's Thor desc/def.

Pure bytes <-> frame conversion. A frame is a map with string keys (the wire shape). No I/O, no transport — the sans-IO seam the conformance corpus exercises directly. Mirrors Terminalwire::V2::Codec.

Builders for each frame type — the wire shape defined in one place. Every builder returns a map with string keys. Mirrors Terminalwire::V2::Frames.

Pure handshake negotiation: given what the client speaks and what the server supports, decide the agreed protocol version and capability set. A function, not a state machine — identical across languages (conformance/vectors/negotiate). Mirrors Terminalwire::V2::Negotiator.

Wire-level constants for the Terminalwire v2 protocol. Mirrors the Ruby Terminalwire::V2::Protocol and the language-neutral conformance corpus — see the protocol spec. These values are part of the cross-language contract; do not change them without a corpus vector to match.

Error codes carried on a failed response.

Names carried by a signal frame.

Frame type tokens (the t field).

Raised when bytes off the wire are not a well-formed frame.

Raised server-side when a response comes back with ok: false.

The seam between a WebSocket endpoint and Terminalwire. Your transport (Phoenix.Socket, Plug.Cowboy WebSock, raw Cowboy) implements this by forwarding binary frames in and providing a way to push binary frames out.

The server-role protocol state machine. Sans-IO: feed it an incoming frame with receive_frame/2, get back {new_state, directives}. A directive is one of

The server's handle on the client's terminal — the API your CLI code calls. Output (puts/print/warn) is fire-and-forget; input and resource ops (gets, read_secret, file/env reads) are synchronous request/response. Mirrors Terminalwire::V2::Server::Context.

An Erlang I/O-protocol device backed by a Terminalwire session. Set as the CLI handler's group leader (see Terminalwire.Server.Session), it routes the standard IO — IO.puts/IO.gets/IO.write, IO.ANSI, :io.columns, and any library built on them (e.g. Owl) — over the wire to the client's terminal, with no Context threading. This mirrors the Ruby server's Server.redirect, which points $stdout/$stdin at the client.

Drives a Terminalwire.Server.Connection over a real transport. This is the process that sits between the WebSocket endpoint and your CLI code

The client's terminal, as seen by the server. A typed view over the raw handshake terminal map so server code reads t.cols / t.tty? instead of digging through string-keyed maps. Mirrors the Ruby server's Terminal accessor.

A ready-made WebSock handler that bridges a WebSocket connection to a Terminalwire.Server.Session. WebSock is the common interface spoken by Phoenix, Bandit, and Plug.Cowboy, so this one module wires Terminalwire into all of them.

The flow-control credit rule as a pure ledger — no processes, no I/O. Mirrors Ruby's Terminalwire::V2::Window and the Go protocol.Window, and is validated by the shared flow conformance corpus. The blocking behaviour when credit runs out is an implementation concern layered on top (the Session); this is just the protocol arithmetic: how much output may be in flight and how window_adjust extends it.