Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 3m54s
feat(app): add minimal size argument for App.start Read more corresponding inputs from stdin and convert them correctly (i.e. in band window resizing), further keys (arrow keys, F-keys, etc.). Respect the provided minimal size for the application which posts an error message in case the size is smaller than the requested minimal size.
128 lines
4.5 KiB
Zig
128 lines
4.5 KiB
Zig
const std = @import("std");
|
|
const zterm = @import("zterm");
|
|
|
|
const App = zterm.App(
|
|
union(enum) {},
|
|
zterm.Renderer.Direct,
|
|
true,
|
|
);
|
|
const Cell = zterm.Cell;
|
|
const Key = zterm.Key;
|
|
const Layout = App.Layout;
|
|
const Widget = App.Widget;
|
|
|
|
const log = std.log.scoped(.tui);
|
|
|
|
pub fn main() !void {
|
|
errdefer |err| log.err("Application Error: {any}", .{err});
|
|
|
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
|
defer arena.deinit();
|
|
|
|
const allocator = arena.allocator();
|
|
|
|
var app: App = .{};
|
|
var renderer: App.Renderer = .{};
|
|
|
|
// FIXME: the layout creates an 'incorrect alignment'?
|
|
var layout = Layout.createFrom(layout: {
|
|
var layout = Layout.VContainer.init(allocator, .{
|
|
.{
|
|
Layout.createFrom(framing: {
|
|
var framing = Layout.Framing.init(allocator, .{
|
|
.title = .{
|
|
.str = "Welcome to my terminal website",
|
|
.style = .{
|
|
.ul = .{ .index = 6 },
|
|
.ul_style = .single,
|
|
},
|
|
},
|
|
}, .{
|
|
.layout = Layout.createFrom(hcontainer: {
|
|
var hcontainer = Layout.HContainer.init(allocator, .{
|
|
.{
|
|
Widget.createFrom(text: {
|
|
var text = Widget.Text.init(.left, &[1]Cell{
|
|
.{ .content = "Yves Biener", .style = .{ .bold = true } },
|
|
});
|
|
break :text &text;
|
|
}),
|
|
25,
|
|
},
|
|
.{
|
|
Widget.createFrom(text: {
|
|
var text = Widget.Text.init(.left, &[1]Cell{
|
|
.{ .content = "File name", .style = .{ .bold = true } },
|
|
});
|
|
break :text &text;
|
|
}),
|
|
50,
|
|
},
|
|
.{
|
|
Widget.createFrom(text: {
|
|
var text = Widget.Text.init(.left, &[1]Cell{
|
|
.{ .content = "Contacts", .style = .{ .bold = true } },
|
|
});
|
|
break :text &text;
|
|
}),
|
|
25,
|
|
},
|
|
});
|
|
break :hcontainer &hcontainer;
|
|
}),
|
|
});
|
|
break :framing &framing;
|
|
}),
|
|
10,
|
|
},
|
|
.{
|
|
Layout.createFrom(margin: {
|
|
var margin = Layout.Margin.init(allocator, .{ .left = 15, .right = 15 }, .{
|
|
.widget = Widget.createFrom(text: {
|
|
var text = Widget.Text.init(.default, &[1]Cell{
|
|
.{ .content = "Does this change anything", .style = .{ .ul = .default, .ul_style = .single } },
|
|
});
|
|
break :text &text;
|
|
}),
|
|
});
|
|
break :margin &margin;
|
|
}),
|
|
90,
|
|
},
|
|
});
|
|
break :layout &layout;
|
|
});
|
|
defer layout.deinit();
|
|
|
|
try app.start(null);
|
|
defer app.stop() catch unreachable;
|
|
|
|
// App.Event loop
|
|
while (true) {
|
|
const event = app.nextEvent();
|
|
|
|
switch (event) {
|
|
.quit => break,
|
|
.resize => |size| {
|
|
renderer.resize(size);
|
|
},
|
|
.key => |key| {
|
|
// ctrl+c to quit
|
|
if (Key.matches(key, .{ .cp = 'c', .mod = .{ .ctrl = true } })) {
|
|
app.quit();
|
|
}
|
|
},
|
|
.err => |err| {
|
|
log.err("Received {any} with message: {s}", .{ err.err, err.msg });
|
|
},
|
|
else => {},
|
|
}
|
|
|
|
const events = try layout.handle(event);
|
|
for (events.items) |e| {
|
|
app.postEvent(e);
|
|
}
|
|
try layout.render(&renderer);
|
|
}
|
|
}
|