grace/tpb

Tee your Paste Board

git clone https://git.gae.moe/grace/tpb

Grace Yoderfeat: added ForkOut backend and now forks out to `xclip` and `wl-copy` on linuxc228995

main
621 B24 linesraw
1/// ForkOut Clipboard backend
2/// Fulfills `Clip` interface
3pub const ForkOut = @This();
4
5const std = @import("std");
6
7extern fn sendPB(text: [*:0]const u8) void;
8extern fn initPB() void;
9
10io: std.Io,
11
12child: std.process.Child,
13
14pub fn init(io: std.Io, argv: []const []const u8) !ForkOut {
15    return .{ .child = try std.process.spawn(io, .{ .argv = argv, .stdin = .pipe }), .io = io };
16}
17
18pub fn writeCopyBuffer(self: *ForkOut, buf: []const u8) anyerror!void {
19    try self.child.stdin.?.writeStreamingAll(self.io, buf);
20}
21
22pub fn writePasteboard(self: *ForkOut) anyerror!void {
23    self.child.stdin.?.close(self.io);
24}