diff options
| author | Grace Yoder <grace_yoder@outlook.com> | 2026-06-30 10:02:29 -0600 |
|---|---|---|
| committer | Grace Yoder <grace_yoder@outlook.com> | 2026-06-30 16:33:26 -0600 |
| commit | 9a377fa209cfecf53343247d197dc8578d6c2a1d (patch) | |
| tree | 363b610d822ef6b855cf31873dfa097dd436d38f /src/Clip | |
| parent | 565174c4b8c73e9e28524709060335a0b17ee3fb (diff) | |
feat(NSPasteboard): uses backend when not ssh and on MacOS
Diffstat (limited to 'src/Clip')
| -rw-r--r-- | src/Clip/NSPasteboard.zig | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/Clip/NSPasteboard.zig b/src/Clip/NSPasteboard.zig index 92c3403..acb895a 100644 --- a/src/Clip/NSPasteboard.zig +++ b/src/Clip/NSPasteboard.zig @@ -1,8 +1,44 @@ +/// NSPasteBoard Clipboard backend +/// Fulfills `Clip` interface +pub const NSPasteboard = @This(); + const std = @import("std"); extern fn sendPB(text: [*:0]const u8) void; extern fn initPB() void; +alloc: std.mem.Allocator, +io: std.Io, + +buffer: std.ArrayList(u8), + +pub fn init(alloc: std.mem.Allocator, io: std.Io, buf_size: usize) !NSPasteboard { + return .{ + .alloc = alloc, + .io = io, + .buffer = try std.ArrayList(u8).initCapacity(alloc, buf_size), + }; +} + +pub fn free(self: *NSPasteboard) void { + self.buffer.clearAndFree(self.alloc); +} + +pub fn writeCopyBuffer(self: *NSPasteboard, buf: []const u8) anyerror!void { + try self.buffer.appendSlice(self.alloc, buf); +} + +pub fn writePasteboard(self: *NSPasteboard) anyerror!void { + // Null Terminate string for C function Call + if (self.buffer.items[self.buffer.items.len - 1] == '\n') { + self.buffer.items[self.buffer.items.len - 1] = '\x00'; + } else { + try self.buffer.append(self.alloc, '\x00'); + } + initPB(); + sendPB(@ptrCast(self.buffer.items.ptr)); +} + test "objc bridge" { initPB(); sendPB("test_string"); @@ -15,4 +51,3 @@ test "objc bridge" { try std.testing.expectEqualStrings("test_string", std.mem.trim(u8, result.stdout, "\n")); } - |
