image: fix base64 and example
This commit is contained in:
parent
df2f936317
commit
5ad01f6a3a
2 changed files with 9 additions and 7 deletions
|
@ -18,11 +18,13 @@ pub fn main() !void {
|
|||
}
|
||||
const alloc = gpa.allocator();
|
||||
|
||||
var vx = try vaxis.init(Event, .{});
|
||||
var vx = try vaxis.init(alloc, .{});
|
||||
defer vx.deinit(alloc);
|
||||
|
||||
try vx.startReadThread();
|
||||
defer vx.stopReadThread();
|
||||
var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };
|
||||
|
||||
try loop.run();
|
||||
defer loop.stop();
|
||||
|
||||
try vx.enterAltScreen();
|
||||
|
||||
|
@ -38,7 +40,7 @@ pub fn main() !void {
|
|||
var n: usize = 0;
|
||||
|
||||
while (true) {
|
||||
const event = vx.nextEvent();
|
||||
const event = loop.nextEvent();
|
||||
switch (event) {
|
||||
.key_press => |key| {
|
||||
if (key.matches('c', .{ .ctrl = true })) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const std = @import("std");
|
||||
const atomic = std.atomic;
|
||||
const base64 = std.base64;
|
||||
const base64Encoder = std.base64.standard.Encoder;
|
||||
const zigimg = @import("zigimg");
|
||||
|
||||
const Cell = @import("Cell.zig");
|
||||
|
@ -580,8 +580,8 @@ pub fn loadImage(
|
|||
const png_buf = try alloc.alloc(u8, img.imageByteSize());
|
||||
defer alloc.free(png_buf);
|
||||
const png = try img.writeToMemory(png_buf, .{ .png = .{} });
|
||||
const b64_buf = try alloc.alloc(u8, base64.calcSize(png.len));
|
||||
const encoded = base64.encode(b64_buf, png);
|
||||
const b64_buf = try alloc.alloc(u8, base64Encoder.calcSize(png.len));
|
||||
const encoded = base64Encoder.encode(b64_buf, png);
|
||||
defer alloc.free(b64_buf);
|
||||
|
||||
const id = self.next_img_id;
|
||||
|
|
Loading…
Reference in a new issue