home
tpb

repository View

feat(OSC52): added tmux mode to use tmux passthrough

change ID
wltktvzrqsqoszszpryllpksnkwsqpnt
git commit
130e668dd511466797d0fb75c0ef23e0c2e382cb
author
Grace Yoder <grace_yoder@outlook.com> - 2026-07-06T13:35:03-06:00
committer
Grace Yoder <grace_yoder@outlook.com> - 2026-07-06T17:15:47-06:00
parents
zwlvrkvuoynx
refs
signature
Present (not validated)
feat(OSC52): added tmux mode to use tmux passthrough

tree

type name size
file .crow/build.yml 1532 bytes
file .crow/release.yml 566 bytes
file .gitignore 354 bytes
file LICENSE 1073 bytes
file README.md 632 bytes
file build.zig 2345 bytes
file build.zig.zon 247 bytes
file src/Clip/ForkOut.zig 621 bytes
file src/Clip/NSPBBridge.m 382 bytes
file src/Clip/NSPasteboard.zig 1456 bytes
file src/Clip/OSC52.zig 5317 bytes
file src/Clip.zig 1560 bytes
file src/main.zig 2918 bytes

diff

src/Clip/OSC52.zig

modified (file → file)

--- a/src/Clip/OSC52.zig
+++ b/src/Clip/OSC52.zig
@@ -12,6 +12,8 @@
 leftover_bytes: [3]u8,
 leftover_count: u8,
 
+is_tmux: bool,
+
 const base64encoder =
     std.base64.Base64Encoder.init(std.base64.standard_alphabet_chars, '=');
 
@@ -22,6 +24,7 @@
         .base64buffer = try std.ArrayList(u8).initCapacity(alloc, buf_size),
         .leftover_bytes = undefined,
         .leftover_count = 0,
+        .is_tmux = false,
     };
 }
 
@@ -71,25 +74,54 @@
     try self.encodeRemaining();
 
     // https://ghostty.org/docs/vt/osc/52
-    const osc_header = &[_]u8{
-        0x1b, // ESC
-        0x5d, // ']'
-        0x35, 0x32, // Code 52
-        0x3b, // ';'
-        // 0x70, // 'p' Primary Clipboard
-        0x63, // 'c' Standard Clipboard
-        0x3b, // ';'
-    };
-    const osc_footer = &[_]u8{
-        0x1b, // ESC
-        0x5c, // '\'
-    };
 
     // Write data to stdout
     const stdout = std.Io.File.stdout();
-    try stdout.writeStreamingAll(self.io, osc_header);
+    try stdout.writeStreamingAll(self.io, self.osc_header());
     try stdout.writeStreamingAll(self.io, self.base64buffer.items);
-    try stdout.writeStreamingAll(self.io, osc_footer);
+    try stdout.writeStreamingAll(self.io, self.osc_footer());
+}
+
+fn osc_header(self: *OSC52) []const u8 {
+    if (self.is_tmux) {
+        return &[_]u8{
+            0x1b, // ESC
+            'P', 't', 'm', 'u', 'x', ';', // tmux escape
+            0x1b, 0x1b, // ESC ESC
+            0x5d, // ']'
+            0x35, 0x32, // Code 52
+            0x3b, // ';'
+            // 0x70, // 'p' Primary Clipboard
+            0x63, // 'c' Standard Clipboard
+            0x3b, // ';'
+        };
+    } else {
+        return &[_]u8{
+            0x1b, // ESC
+            0x5d, // ']'
+            0x35, 0x32, // Code 52
+            0x3b, // ';'
+            // 0x70, // 'p' Primary Clipboard
+            0x63, // 'c' Standard Clipboard
+            0x3b, // ';'
+        };
+    }
+}
+
+fn osc_footer(self: *OSC52) []const u8 {
+    if (self.is_tmux) {
+        return &[_]u8{
+            0x1b, 0x1b, // ESC ESC
+            0x5c, // '\'
+            0x1b, // ESC
+            0x5c, // '\'
+        };
+    } else {
+        return &[_]u8{
+            0x1b, // ESC
+            0x5c, // '\'
+        };
+    }
 }
 
 test "basic base64 encode" {