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
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m28s
This commit is contained in:
13
src/app.zig
13
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,16 +98,23 @@ pub fn App(comptime M: type, comptime E: type) type {
|
||||
|
||||
if (!this.handler_registered) {
|
||||
handler_ctx = this;
|
||||
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.INT, &.{
|
||||
.handler = .{ .handler = handleInt },
|
||||
.mask = posix.sigemptyset(),
|
||||
.flags = 0,
|
||||
}, null);
|
||||
this.handler_registered = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user