bd44b5aa08
Nix / Required Checks: Nix (push) Blocked by required conditions
Nix / check-zig-cache-hash (push) Waiting to run
Test / skip (push) Waiting to run
Test / Required Checks: Test (push) Blocked by required conditions
Test / build-bench (push) Blocked by required conditions
Test / list-examples (push) Blocked by required conditions
Test / Example ${{ matrix.dir }} (Windows) (push) Blocked by required conditions
Test / Example ${{ matrix.dir }} (push) Blocked by required conditions
Test / build-cmake (push) Blocked by required conditions
Test / test-lib-vt-pkgconfig (push) Blocked by required conditions
Test / build-flatpak (push) Blocked by required conditions
Test / build-snap (push) Blocked by required conditions
Test / build-linux (namespace-profile-ghostty-md-arm64) (push) Blocked by required conditions
Test / build-nix (namespace-profile-ghostty-md) (push) Blocked by required conditions
Test / build-libghostty-vt (aarch64-linux) (push) Blocked by required conditions
Test / build-libghostty-vt (aarch64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt (wasm32-freestanding) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-linux) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-linux-musl) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt (x86_64-windows-gnu) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (aarch64-ios) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (aarch64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt-macos (x86_64-macos) (push) Blocked by required conditions
Test / build-libghostty-vt-android (aarch64-linux-android) (push) Blocked by required conditions
Test / build-libghostty-vt-android (arm-linux-androideabi) (push) Blocked by required conditions
Test / build-libghostty-vt-android (x86_64-linux-android) (push) Blocked by required conditions
Test / build-libghostty-vt-windows (push) Blocked by required conditions
Test / build-libghostty-windows-gnu (push) Blocked by required conditions
Test / build-linux (namespace-profile-ghostty-md) (push) Blocked by required conditions
Test / build-linux-libghostty (push) Blocked by required conditions
Test / build-nix (namespace-profile-ghostty-md-arm64) (push) Blocked by required conditions
Test / build-dist (push) Blocked by required conditions
Test / build-dist-lib-vt (push) Blocked by required conditions
Test / trigger-snap (push) Blocked by required conditions
Test / trigger-flatpak (push) Blocked by required conditions
Test / build-macos (push) Blocked by required conditions
Test / build-macos-freetype (push) Blocked by required conditions
Test / test (push) Blocked by required conditions
Test / test-lib-vt (push) Blocked by required conditions
Test / GTK x11=false wayland=false (push) Blocked by required conditions
Test / GTK x11=true wayland=false (push) Blocked by required conditions
Test / GTK x11=false wayland=true (push) Blocked by required conditions
Test / GTK x11=true wayland=true (push) Blocked by required conditions
Test / Build -Dsimd=false (push) Blocked by required conditions
Test / Build -Dsimd=true (push) Blocked by required conditions
Test / Build -Dsentry=false (push) Blocked by required conditions
Test / Build -Dsentry=true (push) Blocked by required conditions
Test / test-macos (push) Blocked by required conditions
Test / test-windows (push) Blocked by required conditions
Test / Build -Di18n=false (push) Blocked by required conditions
Test / Build -Di18n=true (push) Blocked by required conditions
Test / Build test/fuzz-libghostty (push) Blocked by required conditions
Test / zig-fmt (push) Blocked by required conditions
Test / GitHub Actions Pins (push) Blocked by required conditions
Test / prettier (push) Blocked by required conditions
Test / swiftlint (push) Blocked by required conditions
Test / alejandra (push) Blocked by required conditions
Test / typos (push) Blocked by required conditions
Test / shellcheck (push) Blocked by required conditions
Test / translations (push) Blocked by required conditions
Test / blueprint-compiler (push) Blocked by required conditions
Test / Test pkg/wuffs (push) Blocked by required conditions
Test / Test build on Debian 13 (push) Blocked by required conditions
Test / valgrind (push) Blocked by required conditions
102 lines
2.9 KiB
C
102 lines
2.9 KiB
C
/**
|
|
* @file paste.h
|
|
*
|
|
* Paste utilities - validate and encode paste data for terminal input.
|
|
*/
|
|
|
|
#ifndef GHOSTTY_VT_PASTE_H
|
|
#define GHOSTTY_VT_PASTE_H
|
|
|
|
/** @defgroup paste Paste Utilities
|
|
*
|
|
* Utilities for validating and encoding paste data for terminal input.
|
|
*
|
|
* ## Basic Usage
|
|
*
|
|
* 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.
|
|
*
|
|
* ## Examples
|
|
*
|
|
* ### Safety Check
|
|
*
|
|
* @snippet c-vt-paste/src/main.c paste-safety
|
|
*
|
|
* ### Encoding
|
|
*
|
|
* @snippet c-vt-paste/src/main.c paste-encode
|
|
*
|
|
* @{
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <ghostty/vt/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
* Check if paste data is safe to paste into the terminal.
|
|
*
|
|
* Data is considered unsafe if it contains:
|
|
* - Newlines (`\n`) which can inject commands
|
|
* - The bracketed paste end sequence (`\x1b[201~`) which can be used
|
|
* to exit bracketed paste mode and inject commands
|
|
*
|
|
* This check is conservative and considers data unsafe regardless of
|
|
* current terminal state.
|
|
*
|
|
* @param data The paste data to check (must not be NULL)
|
|
* @param len The length of the data in bytes
|
|
* @return true if the data is safe to paste, false otherwise
|
|
*/
|
|
GHOSTTY_API bool ghostty_paste_is_safe(const char* data, size_t len);
|
|
|
|
/**
|
|
* Encode paste data for writing to the terminal pty.
|
|
*
|
|
* This function prepares paste data for terminal input by:
|
|
* - Stripping unsafe control bytes (NUL, ESC, DEL, etc.) by replacing
|
|
* them with spaces
|
|
* - Wrapping the data in bracketed paste sequences if @p bracketed is true
|
|
* - Replacing newlines with carriage returns if @p bracketed is false
|
|
*
|
|
* The input @p 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 @p out_written.
|
|
* The caller can then retry with a sufficiently sized buffer.
|
|
*
|
|
* @param data The paste data to encode (modified in place, may be NULL)
|
|
* @param data_len The length of the input data in bytes
|
|
* @param bracketed Whether bracketed paste mode is active
|
|
* @param buf Output buffer to write the encoded result into (may be NULL)
|
|
* @param buf_len Size of the output buffer in bytes
|
|
* @param[out] out_written On success, the number of bytes written. On
|
|
* GHOSTTY_OUT_OF_SPACE, the required buffer size.
|
|
* @return GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_SPACE if the buffer
|
|
* is too small
|
|
*/
|
|
GHOSTTY_API GhosttyResult ghostty_paste_encode(
|
|
char* data,
|
|
size_t data_len,
|
|
bool bracketed,
|
|
char* buf,
|
|
size_t buf_len,
|
|
size_t* out_written);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
/** @} */
|
|
|
|
#endif /* GHOSTTY_VT_PASTE_H */
|