mod(app): remove interupt method, merged with stop
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m13s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m13s
This commit is contained in:
@@ -147,8 +147,8 @@ pub fn main() !void {
|
||||
if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit();
|
||||
|
||||
if (key.eql(.{ .cp = 'n', .mod = .{ .ctrl = true } })) {
|
||||
try app.interrupt();
|
||||
renderer.size = .{}; // reset size, such that next resize will cause a full re-draw!
|
||||
try app.stop();
|
||||
defer renderer.clear() catch @panic("could not clear the screen");
|
||||
defer app.start(.full) catch @panic("could not start app event loop");
|
||||
var child = std.process.Child.init(&.{"vim"}, allocator);
|
||||
_ = child.spawnAndWait() catch |err| app.postEvent(.{
|
||||
@@ -157,7 +157,6 @@ pub fn main() !void {
|
||||
.msg = "Spawning $EDITOR failed",
|
||||
},
|
||||
});
|
||||
continue;
|
||||
}
|
||||
},
|
||||
// NOTE errors could be displayed in another container in case one was received, etc. to provide the user with feedback
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const QuitText = struct {
|
||||
const text = "Press ctrl+c to quit.";
|
||||
const text = "Press ctrl+c or ctrl+d to quit.";
|
||||
|
||||
pub fn element(this: *@This()) App.Element {
|
||||
return .{
|
||||
@@ -142,13 +142,16 @@ pub fn main() !void {
|
||||
|
||||
// handle events
|
||||
for (0..len) |_| {
|
||||
const event = app.queue.pop();
|
||||
const event = app.queue.drain().?;
|
||||
log.debug("received event: {s}", .{@tagName(event)});
|
||||
|
||||
// pre event handling
|
||||
switch (event) {
|
||||
// NOTE draw the character with the ctrl indication and a newline to make sure the rendering stays consistent
|
||||
.cancel => try renderer.writeCtrlDWithNewline(),
|
||||
.cancel => {
|
||||
app.quit();
|
||||
break :event;
|
||||
},
|
||||
.line => |line| {
|
||||
defer gpa.free(line);
|
||||
log.debug("{s}", .{line});
|
||||
@@ -165,15 +168,7 @@ pub fn main() !void {
|
||||
.msg = "Container Event handling failed",
|
||||
},
|
||||
});
|
||||
|
||||
// post event handling
|
||||
switch (event) {
|
||||
.quit => break :event,
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
// if there are more events to process continue handling them otherwise I can render the next frame
|
||||
if (app.queue.len() > 0) continue :event;
|
||||
|
||||
container.resize(&app.model, try renderer.resize());
|
||||
container.reposition(&app.model, .{});
|
||||
|
||||
18
src/app.zig
18
src/app.zig
@@ -91,12 +91,11 @@ pub fn App(comptime M: type, comptime E: type) type {
|
||||
|
||||
pub fn start(this: *@This(), config: TerminalConfiguration) !void {
|
||||
this.config = config;
|
||||
if (this.thread) |_| return;
|
||||
|
||||
if (!this.handler_registered) {
|
||||
// post init event (as the very first element to be in the queue - event loop)
|
||||
this.postEvent(.init);
|
||||
|
||||
if (!this.handler_registered) {
|
||||
handler_ctx = this;
|
||||
if (config.altScreen) {
|
||||
posix.sigaction(posix.SIG.WINCH, &.{
|
||||
@@ -105,11 +104,13 @@ pub fn App(comptime M: type, comptime E: type) type {
|
||||
.flags = 0,
|
||||
}, null);
|
||||
}
|
||||
// only applies to non-raw mode applications
|
||||
posix.sigaction(posix.SIG.CONT, &.{
|
||||
.handler = .{ .handler = handleCont },
|
||||
.mask = posix.sigemptyset(),
|
||||
.flags = 0,
|
||||
}, null);
|
||||
// only applies to non-raw mode applications
|
||||
posix.sigaction(posix.SIG.INT, &.{
|
||||
.handler = .{ .handler = handleInt },
|
||||
.mask = posix.sigemptyset(),
|
||||
@@ -131,25 +132,22 @@ pub fn App(comptime M: type, comptime E: type) type {
|
||||
if (this.config.altScreen and this.config.rawMode) try terminal.enableMouseSupport();
|
||||
}
|
||||
|
||||
pub fn interrupt(this: *@This()) !void {
|
||||
pub fn stop(this: *@This()) !void {
|
||||
this.quit_event.set();
|
||||
if (this.config.altScreen and this.config.rawMode) try terminal.disableMouseSupport();
|
||||
if (this.config.saveScreen) try terminal.restoreScreen();
|
||||
if (this.config.altScreen) try terminal.exitAltScreen();
|
||||
if (this.thread) |*thread| {
|
||||
thread.join();
|
||||
this.thread = null;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(this: *@This()) !void {
|
||||
try this.interrupt();
|
||||
if (this.config.hideCursor) try terminal.showCursor();
|
||||
if (this.config.saveScreen) try terminal.resetCursor();
|
||||
if (this.termios) |termios| {
|
||||
if (this.config.rawMode) try terminal.disableRawMode(&termios);
|
||||
this.termios = null;
|
||||
}
|
||||
if (this.thread) |*thread| {
|
||||
thread.join();
|
||||
this.thread = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Quit the application loop.
|
||||
|
||||
@@ -724,9 +724,6 @@ pub fn TextField(Model: type, Event: type) type {
|
||||
};
|
||||
} // TextField(Model: type, Event: type)
|
||||
|
||||
// TODO features
|
||||
// - clear input (with and without retaining of capacity) through an public api
|
||||
// - make handle / content functions public
|
||||
pub fn Input(Model: type, Event: type, Queue: type) fn (meta.FieldEnum(Event)) type {
|
||||
// NOTE the struct is necessary, as otherwise I cannot point to the function I want to return
|
||||
const input_struct = struct {
|
||||
|
||||
Reference in New Issue
Block a user