Expand description
Kitty OSC 5522 rich-clipboard protocol: request builders, reply parsing, capability hint.
Spec: https://sw.kovidgoyal.net/kitty/clipboard/
VT Code implements the read path only: the TUI falls back to it when a
local OS-clipboard image read fails (SSH, containers, headless sessions).
The write path (type=write/wdata/walias) and paste-event mode
(CSI ? 5522 h) are deliberately out of scope — terminal copy stays on
plain OSC 52 and paste stays on bracketed paste plus this read fallback.
Two consumers share this module:
- the startup color probe (
crate::utilscallers invtcode-core) folds a DECRQM 5522 query into its existing OSC batch and caches the result withset_clipboard_5522_hint; - the TUI session (Phase 1) sends
read_requeston image-paste fallback, receives one reply packet per fork-parser event, and feeds them toReadAssembler.
All parsing is fail-closed: malformed packets, id mismatches, oversized payloads, and terminal error statuses abort the read instead of yielding partial data.
Structs§
- Mime
Data - One fully assembled MIME payload from a 5522 read.
- Read
Assembler - Incremental assembler for one 5522 read:
OK (DATA*) DONE. - Read
Options - Shared options for 5522 read requests.
- Read
Packet - One parsed 5522 read-reply packet (OSC framing already stripped).
Enums§
- Assemble
Error - A 5522 read failed while assembling packets.
- Assemble
Outcome - Outcome of feeding one packet to
ReadAssembler::push. - Packet
Error - A single packet failed to parse.
- Read
Error Code - Terminal error status for a 5522 read.
- Read
Status - Status of one parsed 5522 read-reply packet.
Constants§
- DECRPM_
5522_ PREFIX - Prefix of a DECRPM reply to
DECRQM_5522_QUERY:CSI ? 5522 ; Ps $ y. - DECRQM_
5522_ QUERY - Query for 5522 support:
CSI ? 5522 $ p(DECRQM). - MAX_
PACKET_ BYTES - Upper bound for one 5522 reply packet (base64 payload plus metadata).
- MAX_
READ_ BYTES - Upper bound for the total decoded bytes of one clipboard read.
Functions§
- clipboard_
5522_ available - Whether the session may attempt 5522 clipboard reads.
- clipboard_
5522_ hint - Cached startup-probe verdict, if the probe produced one.
- generate_
request_ id - Generate a random correlation id inside the spec’s charset.
- mime_
list_ request - Build a MIME-list request: payload is base64(
.). - parse_
decrpm_ 5522 - Parse a DECRPM 5522 reply out of a mixed probe buffer.
- parse_
read_ packet - Parse one 5522 reply packet with OSC framing already stripped.
- read_
request - Build a typed read request for space-separated
mimes. - sanitize_
request_ id - Strip characters outside the spec’s request-id charset.
- set_
clipboard_ 5522_ hint - Cache the startup probe’s 5522 verdict (
Noneclears the hint).