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
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 29s
This commit is contained in:
37
src/main.zig
37
src/main.zig
@@ -7,6 +7,8 @@ const App = zterm.App(
|
||||
true,
|
||||
);
|
||||
const Key = zterm.Key;
|
||||
const Layout = App.Layout;
|
||||
const Widget = App.Widget;
|
||||
|
||||
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
|
||||
// -> size hint how much should it use?
|
||||
|
||||
const mainFile = try std.fs.cwd().openFile("./src/main.zig", .{});
|
||||
var mainFileText = App.Widget.RawText.init(allocator, mainFile);
|
||||
mainFile.close();
|
||||
|
||||
const appFile = try std.fs.cwd().openFile("./src/app.zig", .{});
|
||||
var appFileText = App.Widget.RawText.init(allocator, appFile);
|
||||
appFile.close();
|
||||
|
||||
var spacer = App.Widget.Spacer.init();
|
||||
// TODO: corresponding contents need to be filled out by the layout accordingly!
|
||||
var vstack = App.Layout.VStack.init(allocator, .{
|
||||
App.Widget.createFrom(&appFileText),
|
||||
App.Widget.createFrom(&spacer),
|
||||
App.Widget.createFrom(&mainFileText),
|
||||
var layout = Layout.createFrom(layout: {
|
||||
var vstack = Layout.VStack.init(allocator, .{
|
||||
Widget.createFrom(blk: {
|
||||
const file = try std.fs.cwd().openFile("./src/app.zig", .{});
|
||||
defer file.close();
|
||||
var widget = Widget.RawText.init(allocator, file);
|
||||
break :blk &widget;
|
||||
}),
|
||||
Widget.createFrom(blk: {
|
||||
var spacer = Widget.Spacer.init();
|
||||
break :blk &spacer;
|
||||
}),
|
||||
Widget.createFrom(blk: {
|
||||
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();
|
||||
|
||||
try app.start();
|
||||
|
||||
Reference in New Issue
Block a user