diff --git a/examples/direct.zig b/examples/direct.zig index 5bb12f9..5758645 100644 --- a/examples/direct.zig +++ b/examples/direct.zig @@ -76,8 +76,9 @@ pub fn main(init: std.process.Init) !void { var app: App = .init(gpa, io, .{}); var stdout = std.Io.File.stdout(); - var buffer: [4096]u8 = undefined; - var writer = stdout.writerStreaming(io, &buffer); + // var buffer: [4096]u8 = undefined; + // var writer = stdout.writerStreaming(io, &buffer); + var writer = stdout.writerStreaming(io, &.{}); const w = &writer.interface; var renderer = zterm.Renderer.Direct.init(gpa); @@ -158,7 +159,10 @@ pub fn main(init: std.process.Init) !void { defer gpa.free(line); log.debug("{s}", .{line}); - if (std.mem.eql(u8, line, "q\n")) try app.quit(); + if (std.mem.eql(u8, line, "q\n")) { + try app.quit(); + break :event; + } }, // NOTE errors could be displayed in another container in case one was received, etc. to provide the user with feedback .err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }), diff --git a/src/app.zig b/src/app.zig index c19d397..1ce1b61 100644 --- a/src/app.zig +++ b/src/app.zig @@ -28,8 +28,6 @@ pub fn App(comptime M: type, comptime E: type) type { io: std.Io, model: Model, queue: Queue, - // thread: ?Thread = null, - // quit_event: Thread.ResetEvent, future: ?std.Io.Future(@typeInfo(@typeInfo(@TypeOf(run)).@"fn".return_type.?).error_union.error_set!void) = null, termios: ?posix.termios = null, handler_registered: bool = false, @@ -152,11 +150,11 @@ pub fn App(comptime M: type, comptime E: type) type { /// Quit the application loop. /// This will cancel the internal input thread and post a **.quit** `Event`. pub fn quit(this: *@This()) !void { - try this.postEvent(.quit); if (this.future) |*future| { future.cancel(this.io) catch {}; this.future = null; } + try this.postEvent(.quit); } /// Returns the next available event, blocking until one is available. @@ -173,7 +171,8 @@ pub fn App(comptime M: type, comptime E: type) type { // thread to read user inputs var buf: [512]u8 = undefined; // NOTE set the `NONBLOCK` option for the stdin file, such that reading is not blocking! - if (this.config.rawMode) { + // if (this.config.rawMode) { + { // TODO is there a better way to do this through the `std.Io` interface? var fl_flags = posix.system.fcntl(posix.STDIN_FILENO, posix.F.GETFL, 0); fl_flags |= 1 << @bitOffsetOf(posix.system.O, "NONBLOCK");