diff --git a/examples/image.zig b/examples/image.zig index aba084d..8a0ae15 100644 --- a/examples/image.zig +++ b/examples/image.zig @@ -32,6 +32,8 @@ pub fn main() !void { try vx.loadImage(alloc, .{ .path = "examples/zig.png" }), try vx.loadImage(alloc, .{ .path = "examples/vaxis.png" }), }; + defer vx.freeImage(imgs[0].id); + defer vx.freeImage(imgs[1].id); var n: usize = 0; diff --git a/src/vaxis.zig b/src/vaxis.zig index 24790ba..95ef9fd 100644 --- a/src/vaxis.zig +++ b/src/vaxis.zig @@ -646,6 +646,19 @@ pub fn Vaxis(comptime T: type) type { .height = img.height, }; } + + /// deletes an image from the terminal's memory + pub fn freeImage(self: Self, id: u32) void { + var tty = self.tty orelse return; + const writer = tty.buffered_writer.writer(); + std.fmt.format(writer, "\x1b_Ga=d,d=I,i={d};\x1b\\", .{id}) catch |err| { + log.err("couldn't delete image {d}: {}", .{ id, err }); + return; + }; + tty.buffered_writer.flush() catch |err| { + log.err("couldn't flush writer: {}", .{err}); + }; + } }; }