OSC 5522 Clipboard by MIME Type
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.
| Sequence | Does |
|---|---|
OSC 5522 ; type=read ; types ST | read the clipboard as these MIME types; . as the list asks which types it holds |
OSC 5522 ; type=write ST | start writing the clipboard |
OSC 5522 ; type=wdata:mime=type ; data ST | a chunk of data, at most 4096 bytes before encoding, for one MIME type |
OSC 5522 ; type=wdata ST | the 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
| Terminal | Version | Support | Notes |
|---|---|---|---|
| VT220 | manual, 2nd ed., 1984 | No | OSC is not among the controls it recognizes (§4.2) |
| VT510 | manual, 1st ed., 1993 | No | ignores an OSC string (chapter 4) |
| xterm | patch 412, xterm-411a | No | ignored; DECRQM reports mode 5522 as 0 |
| libghostty-vt | 0f171f6 | Yes | passed to the host’s clipboard callbacks; without them it answers EPERM or ENOSYS (OSC5522-1, OSC5522-2) |
| Konsole | 26.11.70, a24c3d71 | No | not in its source |
| kitty | 0.49.2, its documentation | Yes | Copying all data types to the clipboard |
| ConEmu | build 230724, its documentation | No | not 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