![]() |
libghostty-vt 0.0.0
|
Paste into a terminal, and check paste data for unsafe content. More...
Paste into a terminal, and check paste data for unsafe content.
Paste into a terminal with ghostty_terminal_paste(), or validate and encode paste data without one.
What a paste writes depends on the terminal's modes, and ghostty_terminal_paste() reads them itself. If you have a terminal, that's the function you want.
Full program: c-vt-paste/src/main.c
The Input guide covers what a paste writes and how unsafe pastes are refused.
Enumerations | |
| enum | GhosttyPasteSource { GHOSTTY_PASTE_SOURCE_CLIPBOARD = 0 , GHOSTTY_PASTE_SOURCE_TEXT = 1 , GHOSTTY_PASTE_SOURCE_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE } |
Functions | |
| GHOSTTY_API GhosttyResult | ghostty_terminal_paste (GhosttyTerminal terminal, const GhosttyPaste *paste, bool *out_pasted) |
| GHOSTTY_API bool | ghostty_paste_is_safe (const char *data, size_t len) |
| GHOSTTY_API GhosttyResult | ghostty_paste_encode (char *data, size_t data_len, bool bracketed, uint8_t *buf, size_t buf_len, size_t *out_written) |
Data Structures | |
| struct | GhosttyPaste |
| enum GhosttyPasteSource |
Why a paste happened.
| GHOSTTY_API GhosttyResult ghostty_paste_encode | ( | char * | data, |
| size_t | data_len, | ||
| bool | bracketed, | ||
| uint8_t * | buf, | ||
| size_t | buf_len, | ||
| size_t * | out_written ) |
Encode paste data for writing to the terminal pty.
This function prepares paste data for terminal input by:
bracketed is truebracketed is falseThe input data buffer is modified in place during encoding. The encoded result (potentially with bracketed paste prefix/suffix) is written to the output buffer.
If buf is too small, this returns GHOSTTY_OUT_OF_SPACE, sets out_written to the size needed, and leaves buf unchanged. To get the size first, pass NULL for buf and 0 for buf_len. An empty result needs no space, so empty input with bracketed false returns GHOSTTY_SUCCESS with out_written set to 0.
The function modifies data even when it returns GHOSTTY_OUT_OF_SPACE. Encoding the modified data again gives the same result, so you can retry with the same data and a larger buffer:
This is the encoder ghostty_terminal_paste() uses for a text paste; use it directly when there is no terminal to paste into.
| data | The paste data to encode (modified in place, may be NULL) | |
| data_len | The length of the input data in bytes | |
| bracketed | Whether bracketed paste mode is active | |
| buf | Buffer to write the encoded result into. May be NULL if buf_len is 0. | |
| buf_len | Size of buf in bytes | |
| [out] | out_written | The number of bytes written, or the size needed if the result is GHOSTTY_OUT_OF_SPACE |
| GHOSTTY_API bool ghostty_paste_is_safe | ( | const char * | data, |
| size_t | len ) |
Check if paste data is safe to paste into the terminal.
Data is considered unsafe if it contains:
This check is conservative and considers data unsafe regardless of current terminal state. ghostty_terminal_paste() applies the terminal-state-aware rule itself (line terminators are safe inside a bracketed paste); use this to apply the stricter rule on top.
| data | The paste data to check (must not be NULL) |
| len | The length of the data in bytes |
| GHOSTTY_API GhosttyResult ghostty_terminal_paste | ( | GhosttyTerminal | terminal, |
| const GhosttyPaste * | paste, | ||
| bool * | out_pasted ) |
Paste into the terminal according to its current state: a Kitty clipboard protocol paste event if mode 5522 is enabled and a clipboard_read callback is installed, otherwise the text framed per mode 2004. See Paste for the full behavior. Output streams through the write_pty callback in chunks. The viewport is not scrolled; that is up to you, as for key input.
A paste event records a session grant for its one-time password only once the event is written; a failed call never leaves a grant for an event that was never sent.
| terminal | The terminal handle | |
| paste | The paste request, borrowed for the duration of the call | |
| [out] | out_pasted | On success, whether anything was written to the pty (the encoded text or a paste event). False means there was nothing to paste: no non-empty text representation. May be NULL. |
out_pasted); GHOSTTY_REJECTED if the text could inject commands and GhosttyPaste::allow_unsafe is false (nothing was written); GHOSTTY_INVALID_VALUE for a NULL terminal or paste, MIME types without a reader, or when no write_pty callback is installed; GHOSTTY_OUT_OF_MEMORY; GHOSTTY_IO_ERROR if the reader failed or there is no secure entropy source to mint a paste event password (wasm32-freestanding without GHOSTTY_SYS_OPT_RANDOM_SECURE set). Errors write nothing.