add/mod the following features
- split structure for better inclusions - create PlainRenderer to render contents to the terminal - simplify events - clearify what structs are created on the heap and which are on the stack - quit event is now emitted from the main event loop and not the input loop (see helper function `App.quit`) - rename several variables and/or functions for easier understanding - introduce `App.interrupt` to stop the input thread and start a new sub TUI which takes over the entire screen (i.e. 'hx', 'nvim', etc.)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const std = @import("std");
|
||||
const terminal = @import("../terminal.zig");
|
||||
const isTaggedUnion = @import("../event.zig").isTaggedUnion;
|
||||
const Error = @import("../event.zig").Error;
|
||||
|
||||
@@ -11,6 +12,7 @@ pub fn Layout(comptime Event: type) type {
|
||||
widget: Widget = undefined,
|
||||
events: std.ArrayList(Event) = undefined,
|
||||
c: std.ArrayList(u8) = undefined,
|
||||
size: terminal.Size = undefined,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, widget: Widget) @This() {
|
||||
return .{
|
||||
@@ -28,6 +30,12 @@ pub fn Layout(comptime Event: type) type {
|
||||
}
|
||||
|
||||
pub fn handle(this: *@This(), event: Event) !*std.ArrayList(Event) {
|
||||
switch (event) {
|
||||
.resize => |size| {
|
||||
this.size = size;
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
this.events.clearRetainingCapacity();
|
||||
if (this.widget.handle(event)) |e| {
|
||||
try this.events.append(e);
|
||||
|
||||
Reference in New Issue
Block a user