fix(terminal): correctly restore termios and screen's during panic_handler
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m1s

This commit is contained in:
2025-10-19 11:44:17 +02:00
parent fee3c796d9
commit 8f90f57f44
2 changed files with 7 additions and 8 deletions

View File

@@ -88,11 +88,11 @@ pub fn App(comptime E: type) type {
pub fn stop(this: *@This()) !void {
try this.interrupt();
if (this.termios) |*termios| {
if (this.termios) |termios| {
try terminal.disableMouseSupport();
try terminal.showCursor();
try terminal.restoreScreen();
try terminal.disableRawMode(termios);
try terminal.disableRawMode(&termios);
try terminal.exitAltScreen();
}
this.termios = null;
@@ -391,9 +391,9 @@ pub fn App(comptime E: type) type {
pub fn panic_handler(msg: []const u8, _: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
terminal.disableMouseSupport() catch {};
terminal.exitAltScreen() catch {};
terminal.showCursor() catch {};
var termios: posix.termios = .{
terminal.restoreScreen() catch {};
terminal.disableRawMode(&.{
.iflag = .{},
.lflag = .{},
.cflag = .{},
@@ -402,9 +402,8 @@ pub fn App(comptime E: type) type {
.line = 0,
.ispeed = undefined,
.ospeed = undefined,
};
terminal.disableRawMode(&termios) catch {};
terminal.restoreScreen() catch {};
}) catch {};
terminal.exitAltScreen() catch {};
std.debug.defaultPanic(msg, ret_addr);
}

View File

@@ -197,7 +197,7 @@ pub fn enableRawMode(bak: *posix.termios) !void {
}
/// Reverts `enableRawMode` to restore initial functionality.
pub fn disableRawMode(bak: *posix.termios) !void {
pub fn disableRawMode(bak: *const posix.termios) !void {
try posix.tcsetattr(
posix.STDIN_FILENO,
.FLUSH,