3 Commits

Author SHA1 Message Date
1f93e24a37 fix: free Document only if allocated otherwise treat as static
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m10s
2026-01-17 21:42:00 +01:00
0ec9839cc7 mod: bump zlog dependency 2026-01-17 21:41:43 +01:00
9ae9dcfce2 mod(nav): button automatically resizes as necessary 2026-01-17 21:39:51 +01:00
4 changed files with 11 additions and 8 deletions

View File

@@ -10,8 +10,8 @@
.hash = "zterm-0.3.0-1xmmEH82HABfsn5imAK8lw93LevIaqNV10g6xfkNj_OT",
},
.zlog = .{
.url = "git+https://gitea.yves-biener.de/yves-biener/zlog#40ced30a574118cd76202c07dc4b2291c3321d3a",
.hash = "zlog-0.16.0-6JSlR-BIAAAZ4fSbV54zbZZ9hnZSeOPnnFtiVjmIy3ID",
.url = "git+https://gitea.yves-biener.de/yves-biener/zlog#b3c8a3ab1ccae1ba50efbdf26d68a18da8594d2c",
.hash = "zlog-0.16.0-6JSlRwNJAACVd89xnhXRHzCnCs7qab9Jcmx11VMS2ZpL",
},
},
.paths = .{

View File

@@ -61,7 +61,6 @@ pub fn main() !void {
var button: NavigationButton(.about) = .init(&app.model, &app.queue);
try header.append(try .init(allocator, .{
.size = .{
.dim = .{ .x = 5 + 2 },
.grow = .vertical,
},
}, button.element()));
@@ -71,7 +70,6 @@ pub fn main() !void {
var button: NavigationButton(.blog) = .init(&app.model, &app.queue);
try header.append(try .init(allocator, .{
.size = .{
.dim = .{ .x = 4 + 2 },
.grow = .vertical,
},
}, button.element()));

View File

@@ -26,7 +26,7 @@ pub const Document = struct {
title: ?[]const u8 = null,
date: ?[]const u8 = null,
content: []const u8 = undefined,
ptr: []const u8,
ptr: ?[]const u8,
const Preemble = enum {
title,
@@ -36,7 +36,7 @@ pub const Document = struct {
pub const invalidPage: @This() = .{
.title = "Page not found",
.content = "Requested page does not exist",
.ptr = undefined,
.ptr = null,
};
pub fn init(content: []const u8) @This() {
@@ -67,8 +67,8 @@ pub const Document = struct {
}
pub fn deinit(this: *@This(), allocator: Allocator) void {
allocator.free(this.ptr);
this.* = .{ .ptr = undefined };
if (this.ptr) |ptr| allocator.free(ptr);
this.* = .{ .ptr = null };
}
};

View File

@@ -22,12 +22,17 @@ pub fn NavigationButton(App: type) fn (std.meta.FieldEnum(App.Event)) type {
return .{
.ptr = this,
.vtable = &.{
.minSize = minSize,
.handle = handle,
.content = content,
},
};
}
fn minSize(_: *anyopaque, _: *const App.Model, _: zterm.Point) zterm.Point {
return .{ .x = @tagName(page).len + 2 };
}
fn handle(ctx: *anyopaque, _: *App.Model, event: App.Event) !void {
const this: *@This() = @ptrCast(@alignCast(ctx));
switch (event) {