![]() |
libghostty
|
Utilities for validating and encoding paste data for terminal input.
Use ghostty_paste_is_safe() to check if paste data contains potentially dangerous sequences before sending it to the terminal.
Use ghostty_paste_encode() to encode paste data for writing to the pty, including bracketed paste wrapping and unsafe byte stripping.
Functions | |
| 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, char *buf, size_t buf_len, size_t *out_written) |
| GHOSTTY_API GhosttyResult ghostty_paste_encode | ( | char * | data, |
| size_t | data_len, | ||
| bool | bracketed, | ||
| char * | 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 the output buffer is too small, the function returns GHOSTTY_OUT_OF_SPACE and sets the required size in out_written. The caller can then retry with a sufficiently sized buffer.
| 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 | Output buffer to write the encoded result into (may be NULL) | |
| buf_len | Size of the output buffer in bytes | |
| [out] | out_written | On success, the number of bytes written. On GHOSTTY_OUT_OF_SPACE, the required buffer size. |
| 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.
| data | The paste data to check (must not be NULL) |
| len | The length of the data in bytes |