mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-20 20:48:06 +00:00
terminal: make Kitty clipboard write limit configurable (#14002)
Add a new `clipboard-write-limit-bytes` option (similar to `scrollback-limit-bytes`) to limit the maximum OSC 5522 write size. Defaults to 32 MB. This also adds a new `GHOSTTY_TERMINAL_OPT_CLIPBOARD_WRITE_MAX_BYTES` option for libghostty-vt embedders to control the same. Kitty has a limit too and it works by truncating all data. I decided on purpose to diverge from this because I don't think truncated binary data is useful. Instead, we reject it so the application knows the write didn't work. We truncate text data, and we try to do it at the nearest complete UTF-8 sequence (if possible). For the future: Kitty spools any write data more than some size (can't remember) to a temp file on disk. We might want to consider doing something similar since we're all in-memory at the moment. This PR doesn't change that.
This commit is contained in:
@@ -1522,6 +1522,30 @@ typedef enum GHOSTTY_ENUM_TYPED {
|
||||
* Input type: GhosttyTerminalClipboardReadFn
|
||||
*/
|
||||
GHOSTTY_TERMINAL_OPT_CLIPBOARD_READ = 38,
|
||||
|
||||
/**
|
||||
* Set the maximum total decoded bytes a single Kitty clipboard protocol
|
||||
* (OSC 5522) write transaction may accumulate. The limit is captured
|
||||
* when a transaction begins; an in-flight transaction keeps the limit
|
||||
* it started with.
|
||||
*
|
||||
* Text data (text/* MIME types and the legacy X11 text names) beyond
|
||||
* the limit is truncated at a UTF-8 boundary and the write still
|
||||
* completes with DONE. Non-text data beyond the limit fails the whole
|
||||
* transaction with EFBIG and nothing reaches the clipboard write
|
||||
* callback, since binary formats are corrupted by truncation.
|
||||
*
|
||||
* Transactions are buffered in memory, so this limit bounds how much
|
||||
* memory a single write can make the terminal allocate. Pass SIZE_MAX
|
||||
* to remove the limit. A NULL value pointer reverts to the built-in
|
||||
* default of 32MiB.
|
||||
*
|
||||
* This limit doesn't apply to OSC 52 writes, which are bounded by the
|
||||
* maximum length of an escape sequence instead.
|
||||
*
|
||||
* Input type: size_t*
|
||||
*/
|
||||
GHOSTTY_TERMINAL_OPT_CLIPBOARD_WRITE_MAX_BYTES = 39,
|
||||
GHOSTTY_TERMINAL_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
|
||||
} GhosttyTerminalOption;
|
||||
|
||||
@@ -1919,6 +1943,15 @@ typedef enum GHOSTTY_ENUM_TYPED {
|
||||
* Output type: bool *
|
||||
*/
|
||||
GHOSTTY_TERMINAL_DATA_CURSOR_AT_PROMPT = 39,
|
||||
|
||||
/**
|
||||
* The configured maximum decoded bytes per Kitty clipboard protocol
|
||||
* (OSC 5522) write transaction. See
|
||||
* GHOSTTY_TERMINAL_OPT_CLIPBOARD_WRITE_MAX_BYTES.
|
||||
*
|
||||
* Output type: size_t *
|
||||
*/
|
||||
GHOSTTY_TERMINAL_DATA_CLIPBOARD_WRITE_MAX_BYTES = 40,
|
||||
GHOSTTY_TERMINAL_DATA_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
|
||||
} GhosttyTerminalData;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user