diff --git a/src/app.zig b/src/app.zig index 6f920a6..0a24060 100644 --- a/src/app.zig +++ b/src/app.zig @@ -71,6 +71,12 @@ pub fn App(comptime M: type, comptime E: type) type { // -> the signal might not work correctly when hosting the application over ssh! this.postEvent(.resize); } + /// registered INT handler to catch ctrl-c to send a `.cancel` + fn handleInt(_: i32) callconv(.c) void { + const this: *@This() = @ptrCast(@alignCast(handler_ctx)); + // NOTE do not quit the application and instead issue a `.cancel` event + this.postEvent(.cancel); + } pub fn init(gpa: Allocator, io: std.Io, model: Model) @This() { return .{ @@ -92,13 +98,20 @@ pub fn App(comptime M: type, comptime E: type) type { if (!this.handler_registered) { handler_ctx = this; - posix.sigaction(posix.SIG.WINCH, &.{ - .handler = .{ .handler = handleWinch }, + if (config.altScreen) { + posix.sigaction(posix.SIG.WINCH, &.{ + .handler = .{ .handler = handleWinch }, + .mask = posix.sigemptyset(), + .flags = 0, + }, null); + } + posix.sigaction(posix.SIG.CONT, &.{ + .handler = .{ .handler = handleCont }, .mask = posix.sigemptyset(), .flags = 0, }, null); - posix.sigaction(posix.SIG.CONT, &.{ - .handler = .{ .handler = handleCont }, + posix.sigaction(posix.SIG.INT, &.{ + .handler = .{ .handler = handleInt }, .mask = posix.sigemptyset(), .flags = 0, }, null);