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:
2024-11-06 15:20:34 +01:00
parent 9ddbb19336
commit 9b165e8f81
10 changed files with 320 additions and 186 deletions

View File

@@ -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);