aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGrace Yoder <grace_yoder@outlook.com>2026-06-30 14:32:23 -0600
committerGrace Yoder <grace_yoder@outlook.com>2026-06-30 16:33:26 -0600
commit63265d1d7e36c4150df3bdc00bfda2391a54b916 (patch)
tree5a428b02873517cd02f5f1bc4c74626fcc052882 /src
parent8062e417f2c40cc45a422f8546b6dd76423cdb38 (diff)
misc: cleanup
Diffstat (limited to 'src')
-rw-r--r--src/Clip.zig3
-rw-r--r--src/Clip/OSC52.zig9
-rw-r--r--src/main.zig34
3 files changed, 26 insertions, 20 deletions
diff --git a/src/Clip.zig b/src/Clip.zig
index b4e1187..299d4c6 100644
--- a/src/Clip.zig
+++ b/src/Clip.zig
@@ -4,7 +4,8 @@ const builtin = @import("builtin");
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
diff --git a/src/Clip/OSC52.zig b/src/Clip/OSC52.zig
index d95fca1..8b751f5 100644
--- a/src/Clip/OSC52.zig
+++ b/src/Clip/OSC52.zig
@@ -3,7 +3,6 @@
pub const OSC52 = @This();
const std = @import("std");
-const Io = std.Io;
alloc: std.mem.Allocator,
io: std.Io,
@@ -13,9 +12,10 @@ base64buffer: std.ArrayList(u8),
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,
@@ -51,7 +51,6 @@ pub fn writeCopyBuffer(self: *OSC52, buf: []const u8) anyerror!void {
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);
}
@@ -87,7 +86,7 @@ pub fn writePasteboard(self: *OSC52) anyerror!void {
};
// 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);
diff --git a/src/main.zig b/src/main.zig
index 0725ae7..bb0aa14 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -10,7 +10,11 @@ pub fn main(init: std.process.Init) !void {
// 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);
}
@@ -19,27 +23,29 @@ pub fn main(init: std.process.Init) !void {
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 {