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