mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-03 18:34:50 +00:00
lib-vt: begin paste utilities exports starting with safe paste
This commit is contained in:
@@ -122,6 +122,7 @@ comptime {
|
||||
@export(&c.key_encoder_free, .{ .name = "ghostty_key_encoder_free" });
|
||||
@export(&c.key_encoder_setopt, .{ .name = "ghostty_key_encoder_setopt" });
|
||||
@export(&c.key_encoder_encode, .{ .name = "ghostty_key_encoder_encode" });
|
||||
@export(&c.paste_is_safe, .{ .name = "ghostty_paste_is_safe" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub const osc = @import("osc.zig");
|
||||
pub const key_event = @import("key_event.zig");
|
||||
pub const key_encode = @import("key_encode.zig");
|
||||
pub const paste = @import("paste.zig");
|
||||
|
||||
// The full C API, unexported.
|
||||
pub const osc_new = osc.new;
|
||||
@@ -33,10 +34,13 @@ pub const key_encoder_free = key_encode.free;
|
||||
pub const key_encoder_setopt = key_encode.setopt;
|
||||
pub const key_encoder_encode = key_encode.encode;
|
||||
|
||||
pub const paste_is_safe = paste.is_safe;
|
||||
|
||||
test {
|
||||
_ = osc;
|
||||
_ = key_event;
|
||||
_ = key_encode;
|
||||
_ = paste;
|
||||
|
||||
// We want to make sure we run the tests for the C allocator interface.
|
||||
_ = @import("../../lib/allocator.zig");
|
||||
|
||||
36
src/terminal/c/paste.zig
Normal file
36
src/terminal/c/paste.zig
Normal file
@@ -0,0 +1,36 @@
|
||||
const std = @import("std");
|
||||
const paste = @import("../../input/paste.zig");
|
||||
|
||||
pub fn is_safe(data: ?[*]const u8, len: usize) callconv(.c) bool {
|
||||
const slice: []const u8 = if (data) |v| v[0..len] else &.{};
|
||||
return paste.isSafe(slice);
|
||||
}
|
||||
|
||||
test "is_safe with safe data" {
|
||||
const testing = std.testing;
|
||||
const safe = "hello world";
|
||||
try testing.expect(is_safe(safe.ptr, safe.len));
|
||||
}
|
||||
|
||||
test "is_safe with newline" {
|
||||
const testing = std.testing;
|
||||
const unsafe = "hello\nworld";
|
||||
try testing.expect(!is_safe(unsafe.ptr, unsafe.len));
|
||||
}
|
||||
|
||||
test "is_safe with bracketed paste end" {
|
||||
const testing = std.testing;
|
||||
const unsafe = "hello\x1b[201~world";
|
||||
try testing.expect(!is_safe(unsafe.ptr, unsafe.len));
|
||||
}
|
||||
|
||||
test "is_safe with empty data" {
|
||||
const testing = std.testing;
|
||||
const empty = "";
|
||||
try testing.expect(is_safe(empty.ptr, 0));
|
||||
}
|
||||
|
||||
test "is_safe with null empty data" {
|
||||
const testing = std.testing;
|
||||
try testing.expect(is_safe(null, 0));
|
||||
}
|
||||
Reference in New Issue
Block a user