a modern tui library written in zig

Fix ambigious ownership for slices passed to setTitle and copyToClipboard

authored by Mason Schmidgall and committed by rockorager.dev ea0c083a 4f6c1fc7

Changed files
+11 -3
src
+2
src/vxfw/App.zig
··· 261 .set_mouse_shape => |shape| self.vx.setMouseShape(shape), 262 .request_focus => |widget| self.wants_focus = widget, 263 .copy_to_clipboard => |content| { 264 self.vx.copyToSystemClipboard(self.tty.writer(), content, self.allocator) catch |err| { 265 switch (err) { 266 error.OutOfMemory => return Allocator.Error.OutOfMemory, ··· 269 }; 270 }, 271 .set_title => |title| { 272 self.vx.setTitle(self.tty.writer(), title) catch |err| { 273 std.log.err("set_title error: {}", .{err}); 274 };
··· 261 .set_mouse_shape => |shape| self.vx.setMouseShape(shape), 262 .request_focus => |widget| self.wants_focus = widget, 263 .copy_to_clipboard => |content| { 264 + defer self.allocator.free(content); 265 self.vx.copyToSystemClipboard(self.tty.writer(), content, self.allocator) catch |err| { 266 switch (err) { 267 error.OutOfMemory => return Allocator.Error.OutOfMemory, ··· 270 }; 271 }, 272 .set_title => |title| { 273 + defer self.allocator.free(title); 274 self.vx.setTitle(self.tty.writer(), title) catch |err| { 275 std.log.err("set_title error: {}", .{err}); 276 };
+9 -3
src/vxfw/vxfw.zig
··· 141 try self.addCmd(.{ .request_focus = widget }); 142 } 143 144 pub fn copyToClipboard(self: *EventContext, content: []const u8) Allocator.Error!void { 145 - try self.addCmd(.{ .copy_to_clipboard = content }); 146 - } 147 148 pub fn setTitle(self: *EventContext, title: []const u8) Allocator.Error!void { 149 - try self.addCmd(.{ .set_title = title }); 150 } 151 152 pub fn queueRefresh(self: *EventContext) Allocator.Error!void {
··· 141 try self.addCmd(.{ .request_focus = widget }); 142 } 143 144 + /// Copy content to clipboard. 145 + /// content is duplicated using self.alloc. 146 + /// Caller retains ownership of their copy of content. 147 pub fn copyToClipboard(self: *EventContext, content: []const u8) Allocator.Error!void { 148 + try self.addCmd(.{ .copy_to_clipboard = try self.alloc.dupe(u8, content) }); 149 + } 150 151 + /// Set window title. 152 + /// title is duplicated using self.alloc. 153 + /// Caller retains ownership of their copy of title. 154 pub fn setTitle(self: *EventContext, title: []const u8) Allocator.Error!void { 155 + try self.addCmd(.{ .set_title = try self.alloc.dupe(u8, title) }); 156 } 157 158 pub fn queueRefresh(self: *EventContext) Allocator.Error!void {