mod(main): improve ergonomics of example src/main.zig implementation
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 29s

This commit is contained in:
2024-11-10 15:19:15 +01:00
parent b314ff7813
commit 7872223c24

View File

@@ -7,6 +7,8 @@ const App = zterm.App(
true, true,
); );
const Key = zterm.Key; const Key = zterm.Key;
const Layout = App.Layout;
const Widget = App.Widget;
const log = std.log.scoped(.default); const log = std.log.scoped(.default);
@@ -28,22 +30,27 @@ pub fn main() !void {
// FIX: when not running fullscreen, the application needs to screen down accordingly to display the contents // FIX: when not running fullscreen, the application needs to screen down accordingly to display the contents
// -> size hint how much should it use? // -> size hint how much should it use?
const mainFile = try std.fs.cwd().openFile("./src/main.zig", .{}); var layout = Layout.createFrom(layout: {
var mainFileText = App.Widget.RawText.init(allocator, mainFile); var vstack = Layout.VStack.init(allocator, .{
mainFile.close(); Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./src/app.zig", .{});
const appFile = try std.fs.cwd().openFile("./src/app.zig", .{}); defer file.close();
var appFileText = App.Widget.RawText.init(allocator, appFile); var widget = Widget.RawText.init(allocator, file);
appFile.close(); break :blk &widget;
}),
var spacer = App.Widget.Spacer.init(); Widget.createFrom(blk: {
// TODO: corresponding contents need to be filled out by the layout accordingly! var spacer = Widget.Spacer.init();
var vstack = App.Layout.VStack.init(allocator, .{ break :blk &spacer;
App.Widget.createFrom(&appFileText), }),
App.Widget.createFrom(&spacer), Widget.createFrom(blk: {
App.Widget.createFrom(&mainFileText), const file = try std.fs.cwd().openFile("./src/main.zig", .{});
defer file.close();
var widget = Widget.RawText.init(allocator, file);
break :blk &widget;
}),
});
break :layout &vstack;
}); });
var layout = App.Layout.createFrom(&vstack);
defer layout.deinit(); defer layout.deinit();
try app.start(); try app.start();