update readme

This commit is contained in:
Tim Culverhouse 2024-04-30 16:00:23 -05:00
parent 6d995fe737
commit 2f83b0d6ca

View file

@ -78,16 +78,18 @@ pub fn main() !void {
} }
const alloc = gpa.allocator(); const alloc = gpa.allocator();
// Initialize Vaxis with our event type // Initialize Vaxis
var vx = try vaxis.init(Event, .{}); var vx = try vaxis.init(alloc, .{});
// deinit takes an optional allocator. If your program is exiting, you can // deinit takes an optional allocator. If your program is exiting, you can
// choose to pass a null allocator to save some exit time. // choose to pass a null allocator to save some exit time.
defer vx.deinit(alloc); defer vx.deinit(alloc);
var loop: vaxis.Loop(Event) = .{};
// Start the read loop. This puts the terminal in raw mode and begins // Start the read loop. This puts the terminal in raw mode and begins
// reading user input // reading user input
try vx.startReadThread(); try loop.run();
defer vx.stopReadThread(); defer loop.stop();
// Optionally enter the alternate screen // Optionally enter the alternate screen
try vx.enterAltScreen(); try vx.enterAltScreen();
@ -108,7 +110,7 @@ pub fn main() !void {
// queue which can serve as the primary event queue for an application // queue which can serve as the primary event queue for an application
while (true) { while (true) {
// nextEvent blocks until an event is in the queue // nextEvent blocks until an event is in the queue
const event = vx.nextEvent(); const event = loop.nextEvent();
std.log.debug("event: {}", .{event}); std.log.debug("event: {}", .{event});
// exhaustive switching ftw. Vaxis will send events if your Event enum // exhaustive switching ftw. Vaxis will send events if your Event enum
// has the fields for those events (ie "key_press", "winsize") // has the fields for those events (ie "key_press", "winsize")
@ -132,12 +134,11 @@ pub fn main() !void {
// locks on the screen. All applications must handle this event // locks on the screen. All applications must handle this event
// unless they aren't using a screen (IE only detecting features) // unless they aren't using a screen (IE only detecting features)
// //
// This is the only call that the core of Vaxis needs an allocator // The allocations are because we keep a copy of each cell to
// for. The allocations are because we keep a copy of each cell to
// optimize renders. When resize is called, we allocated two slices: // optimize renders. When resize is called, we allocated two slices:
// one for the screen, and one for our buffered screen. Each cell in // one for the screen, and one for our buffered screen. Each cell in
// the buffered screen contains an ArrayList(u8) to be able to store // the buffered screen contains an ArrayList(u8) to be able to store
// the grapheme for that cell Each cell is initialized with a size // the grapheme for that cell. Each cell is initialized with a size
// of 1, which is sufficient for all of ASCII. Anything requiring // of 1, which is sufficient for all of ASCII. Anything requiring
// more than one byte will incur an allocation on the first render // more than one byte will incur an allocation on the first render
// after it is drawn. Thereafter, it will not allocate unless the // after it is drawn. Thereafter, it will not allocate unless the