aboutsummaryrefslogtreecommitdiff
path: root/src/Clip/ForkOut.zig
blob: 97c5377558642cf98fed62e2924af5d0478c7e01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/// ForkOut Clipboard backend
/// Fulfills `Clip` interface
pub const ForkOut = @This();

const std = @import("std");

extern fn sendPB(text: [*:0]const u8) void;
extern fn initPB() void;

io: std.Io,

child: std.process.Child,

pub fn init(io: std.Io, argv: []const []const u8) !ForkOut {
    return .{ .child = try std.process.spawn(io, .{ .argv = argv, .stdin = .pipe }), .io = io };
}

pub fn writeCopyBuffer(self: *ForkOut, buf: []const u8) anyerror!void {
    try self.child.stdin.?.writeStreamingAll(self.io, buf);
}

pub fn writePasteboard(self: *ForkOut) anyerror!void {
    self.child.stdin.?.close(self.io);
}