mod: bump zig version to 0.16.0

This commit is contained in:
2026-05-14 11:05:55 +02:00
parent bdf58f5102
commit 24a08e0e62
25 changed files with 721 additions and 701 deletions
+36 -32
View File
@@ -24,16 +24,19 @@ const QuitText = struct {
}
};
pub fn main() !void {
pub fn main(init: std.process.Init) !void {
errdefer |err| log.err("Application Error: {any}", .{err});
const gpa = init.gpa;
const io = init.io;
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer if (gpa.deinit() == .leak) log.err("memory leak", .{});
var app: App = .init(gpa, io, .{});
var stdout = std.Io.File.stdout();
var stdout_buffer: [4096]u8 = undefined;
var writer = stdout.writerStreaming(io, &stdout_buffer);
const w = &writer.interface;
defer w.flush() catch |err| log.err("Could not flush: {any}", .{err});
const allocator = gpa.allocator();
var app: App = .init(allocator, .{}, .{});
var renderer = zterm.Renderer.Buffered.init(allocator);
var renderer = zterm.Renderer.Buffered.init(gpa);
defer renderer.deinit();
var quit_text: QuitText = .{};
@@ -41,7 +44,7 @@ pub fn main() !void {
// TODO what should the demo application do?
// - some sort of chat? -> write messages and have them displayed in a scrollable array at the right hand side?
// - on the left some buttons?
var box = try App.Container.init(allocator, .{
var box = try App.Container.init(gpa, .{
.border = .{
.color = .blue,
.sides = .all,
@@ -55,19 +58,19 @@ pub fn main() !void {
.dim = .{ .y = 90 },
},
}, .{});
try box.append(try App.Container.init(allocator, .{
try box.append(try App.Container.init(gpa, .{
.rectangle = .{ .fill = .lightgreen },
}, .{}));
try box.append(try App.Container.init(allocator, .{
try box.append(try App.Container.init(gpa, .{
.rectangle = .{ .fill = .lightgreen },
}, .{}));
try box.append(try App.Container.init(allocator, .{
try box.append(try App.Container.init(gpa, .{
.rectangle = .{ .fill = .lightgreen },
}, .{}));
var scrollable: App.Scrollable = .init(box, .disabled);
var container = try App.Container.init(allocator, .{
var container = try App.Container.init(gpa, .{
.layout = .{
.gap = 2,
.separator = .{ .enabled = true },
@@ -75,9 +78,9 @@ pub fn main() !void {
.direction = .horizontal,
},
}, quit_text.element());
try container.append(try App.Container.init(allocator, .{}, scrollable.element()));
try container.append(try App.Container.init(gpa, .{}, scrollable.element()));
var nested_container: App.Container = try .init(allocator, .{
var nested_container: App.Container = try .init(gpa, .{
.layout = .{
.direction = .vertical,
.separator = .{
@@ -85,7 +88,7 @@ pub fn main() !void {
},
},
}, .{});
var inner_container: App.Container = try .init(allocator, .{
var inner_container: App.Container = try .init(gpa, .{
.layout = .{
.direction = .vertical,
},
@@ -94,7 +97,7 @@ pub fn main() !void {
.sides = .all,
},
}, .{});
try inner_container.append(try .init(allocator, .{
try inner_container.append(try .init(gpa, .{
.rectangle = .{
.fill = .blue,
},
@@ -103,7 +106,7 @@ pub fn main() !void {
.dim = .{ .y = 5 },
},
}, .{}));
try inner_container.append(try .init(allocator, .{
try inner_container.append(try .init(gpa, .{
.rectangle = .{
.fill = .red,
},
@@ -112,20 +115,20 @@ pub fn main() !void {
.dim = .{ .y = 5 },
},
}, .{}));
try inner_container.append(try .init(allocator, .{
try inner_container.append(try .init(gpa, .{
.rectangle = .{
.fill = .green,
},
}, .{}));
try nested_container.append(inner_container);
try nested_container.append(try .init(allocator, .{
try nested_container.append(try .init(gpa, .{
.size = .{
.grow = .horizontal,
.dim = .{ .y = 1 },
},
}, .{}));
try container.append(nested_container);
try container.append(try App.Container.init(allocator, .{
try container.append(try App.Container.init(gpa, .{
.rectangle = .{ .fill = .blue },
.size = .{
.dim = .{ .x = 30 },
@@ -133,25 +136,26 @@ pub fn main() !void {
}, .{}));
defer container.deinit(); // also de-initializes the children
try app.start(.full);
defer app.stop() catch |err| log.err("Failed to stop application: {any}", .{err});
try app.start(.full, w);
defer app.stop(w) catch |err| log.err("Failed to stop application: {any}", .{err});
// event loop
while (true) {
const event = app.nextEvent();
const event = app.nextEvent() catch break; // error indicates cancled Io
log.debug("received event: {s}", .{@tagName(event)});
// pre event handling
switch (event) {
.key => |key| {
if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit();
if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) try app.quit();
if (key.eql(.{ .cp = 'n', .mod = .{ .ctrl = true } })) {
try app.stop();
defer renderer.clear() catch @panic("could not clear the screen");
defer app.start(.full) catch @panic("could not start app event loop");
var child = std.process.Child.init(&.{"vim"}, allocator);
_ = child.spawnAndWait() catch |err| app.postEvent(.{
try app.stop(w);
try w.flush();
defer renderer.clear(w) catch @panic("could not clear the screen");
defer app.start(.full, w) catch @panic("could not start app event loop");
var child = try std.process.spawn(io, .{ .argv = &.{"vim"} });
_ = child.wait(io) catch |err| try app.postEvent(.{
.err = .{
.err = err,
.msg = "Spawning $EDITOR failed",
@@ -165,7 +169,7 @@ pub fn main() !void {
}
// NOTE returned errors should be propagated back to the application
container.handle(&app.model, event) catch |err| app.postEvent(.{
container.handle(io, &app.model, event) catch |err| try app.postEvent(.{
.err = .{
.err = err,
.msg = "Container Event handling failed",
@@ -178,10 +182,10 @@ pub fn main() !void {
else => {},
}
container.resize(&app.model, try renderer.resize());
container.resize(&app.model, try renderer.resize(w));
container.reposition(&app.model, .{});
try renderer.render(@TypeOf(container), &container, App.Model, &app.model);
try renderer.flush();
try renderer.flush(w);
}
}