This example demonstrates how to use the paste utilities to check if paste data is safe before sending it to the terminal.
#include <stdio.h>
#include <string.h>
void safety_example() {
const char* safe_data = "hello world";
const char* unsafe_data = "rm -rf /\n";
printf("Safe to paste\n");
}
printf("Unsafe! Contains newline\n");
}
}
void encode_example() {
char data[] = "hello\nworld";
char buf[64];
size_t written = 0;
data, strlen(data), true, buf, sizeof(buf), &written);
printf("Encoded %zu bytes: ", written);
fwrite(buf, 1, written, stdout);
printf("\n");
}
}
int main() {
safety_example();
const char *unsafe_escape = "evil\x1b[201~code";
printf("Data with escape sequence is UNSAFE\n");
}
const char *empty_data = "";
printf("Empty data is safe\n");
}
encode_example();
return 0;
}
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 bool ghostty_paste_is_safe(const char *data, size_t len)