Expand description
Terminal Block Protocol (TBP) v1: wire types and codec.
TBP is an OSC escape sequence carrying a MIME bundle, directly inspired by
Jupyter’s display_data message. A tool emits a block as one escape; the
terminal selects the richest MIME representation it can render and falls back
toward text/plain. Terminals that do not understand TBP ignore the escape.
The wire form is documented normatively in
docs/terminal-block-protocol-spec.md; this crate is its reference codec.
See encode and decode for the byte-stream entry points.
Structs§
- BlockId
- Identifier correlating live-block updates (
open/patch/close) and distinguishing concurrent blocks within one session. - Block
Meta - Optional presentation hints attached to a bundle.
- Caps
- What a terminal can render, sent back to a querying tool so it can choose a
representation before emitting. Travels as JSON on the tool’s stdin, not as
an OSC escape, so it is serialized directly rather than through [
crate::wire]. - Emit
Block - Payload of
Message::Emit: a complete block rendered once. - Mime
Bundle - A set of alternative representations of one block, keyed by MIME type. The
terminal renders the richest type it supports and falls back toward
TEXT_PLAIN. Values are JSON: a string for text and image payloads, an object for structured specs (e.g. Vega-Lite). - Open
Block - Payload of
Message::Open: the initial state of a live block. - Patch
Block - Payload of
Message::Patch: an RFC 6902 JSON patch applied to a live block. - Version
- TBP protocol version. Wire form is a bare integer.
Enums§
- Message
- A single TBP message, decoded from one OSC escape.
- Proto
Error - Failure decoding a TBP escape.
- Trust
Tier - How much capability a block’s rendered content is granted. The emitting tool requests a tier; the terminal clamps it by policy.
Constants§
- OSC_
NUMBER - Private-use OSC number that frames every TBP message. Provisional; the final number is coordinated with other terminals before 1.0.
- PROTOCOL_
VERSION - Protocol version this crate emits and is the highest it accepts.
- TEXT_
PLAIN - The mandatory fallback representation every well-formed bundle should carry.
Functions§
- decode
- Parse the content of one OSC escape (the bytes between
ESC ]andST, with the introducer and terminator already stripped) into aMessage. - decode_
with_ sidechannel - Like
decode, but resolvesfile=references throughfile_reader. When an emit carries afile=RELATIVE_PATHparameter instead of an inline base64 payload,file_readeris called with the relative path and must return the raw file bytes. This avoids base64-encoding large payloads (images, PDFs) over the PTY stream. - encode
- Render a message as a complete escape sequence ready to write to the stream.