Skip to main content

Crate termstate

Crate termstate 

Source
Expand description

OSC 7501, the Program Status Protocol, spec revision 0.4.

This crate re-exports termstate_core (builder, encoder, parser, scanner) and termstate_store (the terminal-side record set) under one name. Depend on those directly for no_std use.

use termstate::{Report, State};

let report = Report::builder(State::Done).app("brew").msg("Upgraded 12 packages").build()?;
assert_eq!(report.to_string(), "\x1b]7501;state=done:app=brew:msg=VXBncmFkZWQgMTIgcGFja2FnZXM=\x1b\\");

Modules§

detect
Feature detection from the program side, as a pure state machine.
limits
Hard limits from the “Limits” section of the spec (revision 0.4).
scan
Extracting OSC 7501 sequences from a byte stream, such as the output a multiplexer or PTY wrapper reads from a program.

Structs§

App
A validated program identifier: [A-Za-z0-9_.+-]{1,32}.
Capabilities
What a terminal accepts, from its feature-detection reply.
Id
A validated record id: segment ("/" segment)*, segment [A-Za-z0-9_.+-]{1,32}, at most 128 bytes and 8 levels. The root record has no id; it is represented as Option<Id>::None.
Record
What one record holds: exactly the keys of the last report for its id.
Report
One validated report: exactly what the addressed record holds after it is applied.
ReportBuilder
Builds a Report from unvalidated program input. See Report::builder.
Store
The records of one terminal. See the crate docs.
Text
A free-text value (msg or title): one line of UTF-8 with no control characters, already validated against its limits.

Enums§

Change
One change to the store. Ids are None for the root record.
Error
Why a report was discarded (terminal side) or refused (program side).
Field
A field that a limit or validation error refers to.
Kind
What a blocked program needs from the user.
Message
One OSC 7501 sequence, decoded.
State
A record state. clear is not a state; it is Message::Clear.
Terminator
The string terminator to end a sequence with.

Functions§

parse_body
Parses the body of one OSC 7501 sequence: the bytes after ESC ] 7501 ; and before the string terminator.
sanitize
Makes arbitrary text safe to send as msg or title: every control character (including newline and tab) becomes a space, and text longer than max_bytes is cut at a character boundary and ends with ….
write_clear
Writes state=clear, removing the record id and everything beneath it, or every record when id is None.
write_query
Writes the program’s feature-detection query, OSC 7501 ; ? ST.