feat(terminal): handle OSC 52 clipboard requests
This commit is contained in:
parent
885c9682eb
commit
4bba8d9715
1 changed files with 23 additions and 0 deletions
|
|
@ -206,6 +206,29 @@ pub fn render(self: *Self, theme: *const Widget.Theme) bool {
|
||||||
self.vt.title.clearRetainingCapacity();
|
self.vt.title.clearRetainingCapacity();
|
||||||
self.vt.title.appendSlice(self.allocator, t) catch {};
|
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());
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue