2024-01-19 03:17:26 +01:00
|
|
|
const std = @import("std");
|
|
|
|
const odditui = @import("odditui");
|
|
|
|
|
|
|
|
const log = std.log.scoped(.main);
|
|
|
|
pub fn main() !void {
|
2024-01-19 06:17:57 +01:00
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
defer {
|
|
|
|
const deinit_status = gpa.deinit();
|
|
|
|
//fail test; can't try in defer as defer is executed after we return
|
|
|
|
if (deinit_status == .leak) {
|
|
|
|
log.err("memory leak", .{});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const alloc = gpa.allocator();
|
|
|
|
|
2024-01-19 03:17:26 +01:00
|
|
|
var app: odditui.App(Event) = try odditui.App(Event).init(.{});
|
2024-01-19 06:17:57 +01:00
|
|
|
defer app.deinit(alloc);
|
2024-01-19 03:17:26 +01:00
|
|
|
|
|
|
|
try app.start();
|
|
|
|
defer app.stop();
|
|
|
|
|
|
|
|
outer: while (true) {
|
|
|
|
const event = app.nextEvent();
|
2024-01-19 06:17:57 +01:00
|
|
|
log.debug("event: {}\r\n", .{event});
|
2024-01-19 03:17:26 +01:00
|
|
|
switch (event) {
|
|
|
|
.key_press => |key| {
|
|
|
|
if (key.codepoint == 'c' and key.mods.ctrl) {
|
|
|
|
break :outer;
|
|
|
|
}
|
|
|
|
},
|
2024-01-19 06:17:57 +01:00
|
|
|
.winsize => |ws| {
|
|
|
|
try app.resize(alloc, ws.rows, ws.cols);
|
|
|
|
},
|
2024-01-19 03:17:26 +01:00
|
|
|
else => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Event = union(enum) {
|
|
|
|
key_press: odditui.Key,
|
2024-01-19 06:17:57 +01:00
|
|
|
winsize: odditui.Winsize,
|
2024-01-19 03:17:26 +01:00
|
|
|
mouse: u8,
|
|
|
|
};
|