Ports ZIG/src/lib_vt.zig and terminal/c/* as crates/ghostty-vt-capi (cdylib + staticlib + rlib, soname libghostty-vt.so) implementing the unchanged include/ghostty/vt.h + vt/*.h ABI: OSC parser, SGR parser, key events and key encoding, paste safety, colors, result codes - all 38 native symbols, plus the ghostty_wasm_* helpers on wasm32. Verification: - tests/abi.rs generates a C probe from the headers, compiled with cc, that checks sizeof/alignof/offsetof of every struct/union, every enumerator and #define against Rust, and links every declared symbol; nm -D exports equal the declared functions. - Ghostty's example/c-vt* programs compile unchanged against the Rust library (shared and static) and produce the expected output. - The wasm32 build runs Ghostty's wasm-key-encode/wasm-sgr example scripts unmodified under node (upstream's wasm-sgr tag table is stale vs sgr.h; a regenerated copy checks full output). Test Plan: - cargo test -p ghostty-vt-capi (22 unit + 2 ABI + 5 C + 3 wasm tests)
32 lines
884 B
C
32 lines
884 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ghostty/vt.h>
|
|
|
|
int main() {
|
|
// Test safe paste data
|
|
const char *safe_data = "hello world";
|
|
if (ghostty_paste_is_safe(safe_data, strlen(safe_data))) {
|
|
printf("'%s' is safe to paste\n", safe_data);
|
|
}
|
|
|
|
// Test unsafe paste data with newline
|
|
const char *unsafe_newline = "rm -rf /\n";
|
|
if (!ghostty_paste_is_safe(unsafe_newline, strlen(unsafe_newline))) {
|
|
printf("'%s' is UNSAFE - contains newline\n", unsafe_newline);
|
|
}
|
|
|
|
// Test unsafe paste data with bracketed paste end sequence
|
|
const char *unsafe_escape = "evil\x1b[201~code";
|
|
if (!ghostty_paste_is_safe(unsafe_escape, strlen(unsafe_escape))) {
|
|
printf("Data with escape sequence is UNSAFE\n");
|
|
}
|
|
|
|
// Test empty data
|
|
const char *empty_data = "";
|
|
if (ghostty_paste_is_safe(empty_data, 0)) {
|
|
printf("Empty data is safe\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|