image: implement deleting images from memory
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
parent
8c8c592722
commit
43f73eb895
2 changed files with 15 additions and 0 deletions
|
@ -32,6 +32,8 @@ pub fn main() !void {
|
||||||
try vx.loadImage(alloc, .{ .path = "examples/zig.png" }),
|
try vx.loadImage(alloc, .{ .path = "examples/zig.png" }),
|
||||||
try vx.loadImage(alloc, .{ .path = "examples/vaxis.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;
|
var n: usize = 0;
|
||||||
|
|
||||||
|
|
|
@ -646,6 +646,19 @@ pub fn Vaxis(comptime T: type) type {
|
||||||
.height = img.height,
|
.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});
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue