add(element): interface for injecting user behavior to containers
Some additional refactoring and documentation updates have also been applied.
This commit is contained in:
22
src/app.zig
22
src/app.zig
@@ -27,8 +27,8 @@ const log = std.log.scoped(.app);
|
||||
/// union(enum) {},
|
||||
/// );
|
||||
/// // later on create an `App` instance and start the event loop
|
||||
/// var app: App = .{};
|
||||
/// try app.start(null);
|
||||
/// var app: App = .init;
|
||||
/// try app.start();
|
||||
/// defer app.stop() catch unreachable;
|
||||
/// ```
|
||||
pub fn App(comptime E: type) type {
|
||||
@@ -38,19 +38,29 @@ pub fn App(comptime E: type) type {
|
||||
return struct {
|
||||
pub const Event = mergeTaggedUnions(event.SystemEvent, E);
|
||||
pub const Container = @import("container.zig").Container(Event);
|
||||
pub const Element = @import("element.zig").Element(Event);
|
||||
|
||||
queue: Queue(Event, 256) = .{},
|
||||
thread: ?std.Thread = null,
|
||||
quit_event: std.Thread.ResetEvent = .{},
|
||||
queue: Queue(Event, 256),
|
||||
thread: ?std.Thread,
|
||||
quit_event: std.Thread.ResetEvent,
|
||||
termios: ?std.posix.termios = null,
|
||||
attached_handler: bool = false,
|
||||
prev_size: Size = .{ .cols = 0, .rows = 0 },
|
||||
prev_size: Size,
|
||||
|
||||
pub const SignalHandler = struct {
|
||||
context: *anyopaque,
|
||||
callback: *const fn (context: *anyopaque) void,
|
||||
};
|
||||
|
||||
pub const init: @This() = .{
|
||||
.queue = .{},
|
||||
.thread = null,
|
||||
.quit_event = .{},
|
||||
.termios = null,
|
||||
.attached_handler = false,
|
||||
.prev_size = .{},
|
||||
};
|
||||
|
||||
pub fn start(this: *@This()) !void {
|
||||
if (this.thread) |_| return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user