examples: fix api for main, pathological, table

This commit is contained in:
Tim Culverhouse 2024-04-29 12:35:02 -05:00
parent 41f76e8f03
commit e7915b5dd7
3 changed files with 21 additions and 18 deletions

View file

@ -15,13 +15,15 @@ pub fn main() !void {
const alloc = gpa.allocator();
// Initialize Vaxis
var vx = try vaxis.init(Event, .{});
var vx = try vaxis.init(.{});
defer vx.deinit(alloc);
var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };
// Start the read loop. This puts the terminal in raw mode and begins
// reading user input
try vx.startReadThread();
defer vx.stopReadThread();
try loop.run();
defer loop.stop();
// Optionally enter the alternate screen
try vx.enterAltScreen();
@ -34,7 +36,7 @@ pub fn main() !void {
// queue which can serve as the primary event queue for an application
while (true) {
// nextEvent blocks until an event is in the queue
const event = vx.nextEvent();
const event = loop.nextEvent();
log.debug("event: {}", .{event});
// exhaustive switching ftw. Vaxis will send events if your Event
// enum has the fields for those events (ie "key_press", "winsize")

View file

@ -11,16 +11,18 @@ const Event = union(enum) {
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
var vx = try vaxis.init(Event, .{});
var vx = try vaxis.init(.{});
errdefer vx.deinit(alloc);
try vx.startReadThread();
defer vx.stopReadThread();
var loop: vaxis.Loop(Event) = .{ .vaxis = &vx };
try loop.run();
defer loop.stop();
try vx.enterAltScreen();
try vx.queryTerminal();
while (true) {
const event = vx.nextEvent();
const event = loop.nextEvent();
switch (event) {
.winsize => |ws| {
try vx.resize(alloc, ws);

View file

@ -25,17 +25,16 @@ pub fn main() !void {
const user_list = std.ArrayList(User).fromOwnedSlice(alloc, users_buf);
defer user_list.deinit();
var vx = try vaxis.init(
union(enum) {
key_press: vaxis.Key,
winsize: vaxis.Winsize,
},
.{},
);
var vx = try vaxis.init(.{});
defer vx.deinit(alloc);
try vx.startReadThread();
defer vx.stopReadThread();
var loop: vaxis.Loop(union(enum) {
key_press: vaxis.Key,
winsize: vaxis.Winsize,
}) = .{ .vaxis = &vx };
try loop.run();
defer loop.stop();
try vx.enterAltScreen();
try vx.queryTerminal();
@ -77,7 +76,7 @@ pub fn main() !void {
var event_arena = heap.ArenaAllocator.init(alloc);
defer event_arena.deinit();
const event_alloc = event_arena.allocator();
const event = vx.nextEvent();
const event = loop.nextEvent();
switch (event) {
.key_press => |key| keyEvt: {