mod(app): SIG.INT handler for Ctrl-C which issues a .cancel event
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m28s

This commit is contained in:
2026-02-02 21:28:21 +01:00
parent 6781c43fcc
commit 0bb91cab0d

View File

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