2024-01-19 03:17:26 +01:00
|
|
|
const std = @import("std");
|
2024-01-19 17:13:32 +01:00
|
|
|
const vaxis = @import("vaxis");
|
2024-01-19 03:17:26 +01:00
|
|
|
|
|
|
|
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 17:13:32 +01:00
|
|
|
var vx = try vaxis.init(Event, .{});
|
|
|
|
defer vx.deinit(alloc);
|
2024-01-19 03:17:26 +01:00
|
|
|
|
2024-01-19 17:13:32 +01:00
|
|
|
try vx.start();
|
|
|
|
defer vx.stop();
|
2024-01-19 03:17:26 +01:00
|
|
|
|
2024-01-19 17:58:14 +01:00
|
|
|
try vx.enterAltScreen();
|
|
|
|
|
2024-01-19 03:17:26 +01:00
|
|
|
outer: while (true) {
|
2024-01-19 17:13:32 +01:00
|
|
|
const event = vx.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| {
|
2024-01-19 17:13:32 +01:00
|
|
|
try vx.resize(alloc, ws.rows, ws.cols);
|
2024-01-19 06:17:57 +01:00
|
|
|
},
|
2024-01-19 03:17:26 +01:00
|
|
|
else => {},
|
|
|
|
}
|
2024-01-19 17:31:23 +01:00
|
|
|
|
|
|
|
const win = vx.window();
|
|
|
|
_ = win;
|
2024-01-19 03:17:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Event = union(enum) {
|
2024-01-19 17:13:32 +01:00
|
|
|
key_press: vaxis.Key,
|
|
|
|
winsize: vaxis.Winsize,
|
2024-01-19 03:17:26 +01:00
|
|
|
mouse: u8,
|
|
|
|
};
|