From 4bba8d9715ada5829a553285a7dfc7041f5bb3ba Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 26 Feb 2026 21:30:40 +0100 Subject: [PATCH] feat(terminal): handle OSC 52 clipboard requests --- src/tui/terminal_view.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/tui/terminal_view.zig b/src/tui/terminal_view.zig index d62daf5..e108e7e 100644 --- a/src/tui/terminal_view.zig +++ b/src/tui/terminal_view.zig @@ -206,6 +206,29 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool { self.vt.title.clearRetainingCapacity(); self.vt.title.appendSlice(self.allocator, t) catch {}; }, + .osc_copy => |text| { + // Terminal app wrote to clipboard via OSC 52. + // Add to flow clipboard history and forward to system clipboard. + const owned = tui.clipboard_allocator().dupe(u8, text) catch break; + tui.clipboard_clear_all(); + tui.clipboard_start_group(); + tui.clipboard_add_chunk(owned); + tui.clipboard_send_to_system() catch {}; + }, + .osc_paste_request => { + // Terminal app requested clipboard contents via OSC 52. + // Assemble from flow clipboard history and respond. + if (tui.clipboard_get_history()) |history| { + var buf: std.Io.Writer.Allocating = .init(self.allocator); + defer buf.deinit(); + var first = true; + for (history) |chunk| { + if (first) first = false else buf.writer.writeByte('\n') catch break; + buf.writer.writeAll(chunk.text) catch break; + } + self.vt.vt.respondOsc52Paste(buf.written()); + } + }, } }