a modern tui library written in zig

tty(posix): remove signal handler when we have in-band-resize

Changed files
+26
src
+6
src/Loop.zig
··· 301 301 if (@hasField(Event, "winsize")) { 302 302 return self.postEvent(.{ .winsize = winsize }); 303 303 } 304 + 305 + switch (builtin.os.tag) { 306 + .windows => {}, 307 + // Reset the signal handler if we are receiving in_band_resize 308 + else => self.tty.resetSignalHandler(), 309 + } 304 310 }, 305 311 } 306 312 },
+20
src/posix/Tty.zig
··· 23 23 var handler_mutex: std.Thread.Mutex = .{}; 24 24 var handler_idx: usize = 0; 25 25 26 + var handler_installed: bool = false; 27 + 26 28 /// global tty instance, used in case of a panic. Not guaranteed to work if 27 29 /// for some reason there are multiple TTYs open under a single vaxis 28 30 /// compilation unit - but this is better than nothing ··· 49 51 .flags = 0, 50 52 }; 51 53 try posix.sigaction(posix.SIG.WINCH, &act, null); 54 + handler_installed = true; 52 55 53 56 const self: Posix = .{ 54 57 .fd = fd, ··· 67 70 }; 68 71 if (builtin.os.tag != .macos) // closing /dev/tty may block indefinitely on macos 69 72 posix.close(self.fd); 73 + } 74 + 75 + /// Resets the signal handler to it's default 76 + pub fn resetSignalHandler() void { 77 + if (!handler_installed) return; 78 + handler_installed = false; 79 + var act = posix.Sigaction{ 80 + .handler = posix.SIG.DFL, 81 + .mask = switch (builtin.os.tag) { 82 + .macos => 0, 83 + .linux => posix.empty_sigset, 84 + .freebsd => posix.empty_sigset, 85 + else => @compileError("os not supported"), 86 + }, 87 + .flags = 0, 88 + }; 89 + posix.sigaction(posix.SIG.WINCH, &act, null) catch {}; 70 90 } 71 91 72 92 /// Write bytes to the tty