misc: cleanup
- change ID
- sttmnvllxltvypzrtytroluyuvsxwvxl
- git commit
- 63265d1d7e36c4150df3bdc00bfda2391a54b916
- author
- Grace Yoder <grace_yoder@outlook.com> - 2026-06-30T14:32:23-06:00
- committer
- Grace Yoder <grace_yoder@outlook.com> - 2026-06-30T16:33:26-06:00
- parents
- ktworolnxkzv
- refs
- signature
- Present (not validated)
misc: cleanup
tree
| type | name | size |
|---|---|---|
| file | .crow/build.yml | 2096 bytes |
| file | .crow/release.yml | 566 bytes |
| file | .gitignore | 354 bytes |
| file | LICENSE | 1073 bytes |
| file | README.md | 632 bytes |
| file | build.zig | 1782 bytes |
| file | build.zig.zon | 247 bytes |
| file | src/Clip/NSPBBridge.m | 382 bytes |
| file | src/Clip/NSPasteboard.zig | 1456 bytes |
| file | src/Clip/OSC52.zig | 4564 bytes |
| file | src/Clip.zig | 1510 bytes |
| file | src/main.zig | 2166 bytes |
diff
src/Clip/OSC52.zig
modified (file → file)
pub const OSC52 = @This();
const std = @import("std");
-const Io = std.Io;
alloc: std.mem.Allocator,
io: std.Io,
leftover_bytes: [3]u8,
leftover_count: u8,
-const base64encoder = std.base64.Base64Encoder.init(std.base64.standard_alphabet_chars, '=');
+const base64encoder =
+ std.base64.Base64Encoder.init(std.base64.standard_alphabet_chars, '=');
-pub fn init(alloc: std.mem.Allocator, io: Io, buf_size: usize) !OSC52 {
+pub fn init(alloc: std.mem.Allocator, io: std.Io, buf_size: usize) !OSC52 {
return .{
.alloc = alloc,
.io = io,
const chunkable_length = buf.len - ((buf.len - buf_idx) % 3);
var chunker = std.mem.window(u8, buf[buf_idx..chunkable_length], 3, 3);
while (chunker.next()) |chunk| {
- // var temp: [5]u8 = undefined;
s = OSC52.base64encoder.encode(&temp, chunk);
try self.base64buffer.appendSlice(self.alloc, s);
}
};
// Write data to stdout
- const stdout = Io.File.stdout();
+ const stdout = std.Io.File.stdout();
try stdout.writeStreamingAll(self.io, osc_header);
try stdout.writeStreamingAll(self.io, self.base64buffer.items);
try stdout.writeStreamingAll(self.io, osc_footer);
src/Clip.zig
modified (file → file)
pub const OSC52 = @import("Clip/OSC52.zig");
// Ideally we would make else be `@compileError` but that
// messes up with the interface checking
-pub const NSPasteboard = if (builtin.target.os.tag == .macos) @import("Clip/NSPasteboard.zig") else void;
+pub const NSPasteboard =
+ if (builtin.target.os.tag == .macos) @import("Clip/NSPasteboard.zig") else void;
// I am not sure if this is super idiomatic Zig or if this is bad practice, but
// by ensuring that all Clip backends implement the same methods, we are able
src/main.zig
modified (file → file)
// This program should not be run interactively
if (try File.stdin().isTty(io)) {
- std.debug.print("This program is not meant to be run interactively. Please pipe into this program.\n", .{});
+ std.debug.print(
+ \\ This program is not meant to be run interactively.
+ \\ Please pipe into this program.
+ \\
+ , .{});
std.process.exit(1);
}
const alloc = std.heap.page_allocator;
const size = std.heap.pageSize();
- const is_ssh = init.environ_map.get("SSH_CONNECTION") != null or
+ const is_ssh =
+ init.environ_map.get("SSH_CONNECTION") != null or
init.environ_map.get("SSH_CLIENT") != null or
init.environ_map.get("SSH_TTY") != null;
- // This can be cleaned up
if (is_ssh) {
var clip = try Clip.OSC52.init(alloc, io, size);
defer clip.free();
try run(io, &clip);
- } else {
- if (comptime os == .macos) {
- var clip = try Clip.NSPasteboard.init(alloc, io, size);
- defer clip.free();
- try run(io, &clip);
- } else {
- // No Linux Clipboards yet
- var clip = try Clip.OSC52.init(alloc, io, size);
- defer clip.free();
- try run(io, &clip);
- }
+ return;
+ }
+
+ if (comptime os == .macos) {
+ var clip = try Clip.NSPasteboard.init(alloc, io, size);
+ defer clip.free();
+ try run(io, &clip);
+ return;
}
+
+ // Fallback Clipboard
+ var clip = try Clip.OSC52.init(alloc, io, size);
+ defer clip.free();
+ try run(io, &clip);
}
pub fn run(io: std.Io, clip: anytype) !void {