feat(terminal): handle OSC 52 clipboard requests

This commit is contained in:
CJ van den Berg 2026-02-26 21:30:40 +01:00
parent 885c9682eb
commit 4bba8d9715
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -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());
}
},
}
}