^[control-codes
live in libghostty-vt

Operating system commands

OSC 5522 Clipboard by MIME Type

View as Markdown

Read and write the clipboard by MIME type, with permission and status: kitty's clipboard protocol.

OSC 5522 ; metadata ; payload ST
ECMA-48
§8.3.89 OSC – Operating System Command, p. 51
Specification
Copying all data types to the clipboard, kitty documentation

OSC 5522 ; metadata ; payload ST extends OSC 52 to every kind of data the clipboard holds, each by its MIME type, and adds answers that say whether a request succeeded. Its definition is kitty’s Copying all data types to the clipboard. The metadata is key=value pairs separated by :; MIME types and data are Base64.

SequenceDoes
OSC 5522 ; type=read ; types STread the clipboard as these MIME types; . as the list asks which types it holds
OSC 5522 ; type=write STstart writing the clipboard
OSC 5522 ; type=wdata:mime=type ; data STa chunk of data, at most 4096 bytes before encoding, for one MIME type
OSC 5522 ; type=wdata STthe end of the write

loc=primary uses the primary selection instead. The terminal answers a read with status=OK, a status=DATA sequence for each chunk, and status=DONE, and a write with status=DONE; or with an error: EPERM when permission is refused, ENOSYS when the clipboard asked for is not available, EBUSY, EIO or EINVAL. A program finds out whether the terminal has the protocol with DECRQM for mode 5522, 0 or 4 meaning no.

A default xterm does not have it and ignores it (the OSC numbers it knows), and answers DECRQM for mode 5522 with 0. The cases follow xterm.

libghostty-vt hands the clipboard to its host through the same CLIPBOARD_READ and CLIPBOARD_WRITE callbacks as OSC 52, and without them, as here, answers itself: EPERM to a read and ENOSYS to a write. It too answers DECRQM for mode 5522 with 0. The cases where it answers are known differences.

Support

TerminalVersionSupportNotes
VT220manual, 2nd ed., 1984NoOSC is not among the controls it recognizes (§4.2)
VT510manual, 1st ed., 1993Noignores an OSC string (chapter 4)
xtermpatch 412, xterm-411aNoignored; DECRQM reports mode 5522 as 0
libghostty-vt0f171f6Yespassed to the host’s clipboard callbacks; without them it answers EPERM or ENOSYS (OSC5522-1, OSC5522-2)
Konsole26.11.70, a24c3d71Nonot in its source
kitty0.49.2, its documentationYesCopying all data types to the clipboard
ConEmubuild 230724, its documentationNonot in its ANSI escape codes

Validation

OSC5522-1: A read is not answered

\e]5522;type=read;dGV4dC9wbGFpbg==\e\\  # text/plain
|______|
reply none

OSC5522-2: Nor is a write

\e]5522;type=write\e\\
\e]5522;type=wdata:mime=dGV4dC9wbGFpbg==;SGk=\e\\  # "Hi"
\e]5522;type=wdata\e\\
|______|
reply none

OSC5522-3: Nothing on screen

A
\e]5522;type=write\e\\
\e]5522;type=wdata\e\\
B
|AB____|
cursor 1,3

OSC5522-4: The mode is not recognized

\e[?5522$p
|______|
reply \e[?5522;0$y
Every example on these pages runs in your browser, in libghostty-vt compiled to WebAssembly.