vxfw: add copy_to_clipboard command
Add a command to copy text to the clipboard via OSC 52
This commit is contained in:
parent
50578e5daf
commit
8fc08b55a1
2 changed files with 16 additions and 0 deletions
|
@ -195,6 +195,14 @@ fn handleCommand(self: *App, cmds: *vxfw.CommandList) Allocator.Error!void {
|
|||
.tick => |tick| try self.addTick(tick),
|
||||
.set_mouse_shape => |shape| self.vx.setMouseShape(shape),
|
||||
.request_focus => |widget| self.wants_focus = widget,
|
||||
.copy_to_clipboard => |content| {
|
||||
self.vx.copyToSystemClipboard(self.tty.anyWriter(), content, self.allocator) catch |err| {
|
||||
switch (err) {
|
||||
error.OutOfMemory => return Allocator.Error.OutOfMemory,
|
||||
else => std.log.err("copy error: {}", .{err}),
|
||||
}
|
||||
};
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,10 @@ pub const Command = union(enum) {
|
|||
set_mouse_shape: vaxis.Mouse.Shape,
|
||||
/// Request that this widget receives focus
|
||||
request_focus: Widget,
|
||||
|
||||
/// Try to copy the provided text to the host clipboard. Uses OSC 52. Silently fails if terminal
|
||||
/// doesn't support OSC 52
|
||||
copy_to_clipboard: []const u8,
|
||||
};
|
||||
|
||||
pub const EventContext = struct {
|
||||
|
@ -118,6 +122,10 @@ pub const EventContext = struct {
|
|||
pub fn requestFocus(self: *EventContext, widget: Widget) Allocator.Error!void {
|
||||
try self.addCmd(.{ .request_focus = widget });
|
||||
}
|
||||
|
||||
pub fn copyToClipboard(self: *EventContext, content: []const u8) Allocator.Error!void {
|
||||
try self.addCmd(.{ .copy_to_clipboard = content });
|
||||
}
|
||||
};
|
||||
|
||||
pub const DrawContext = struct {
|
||||
|
|
Loading…
Add table
Reference in a new issue