From 22dca22450c3caf2615880b48109de56aed78cd7 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Tue, 6 Aug 2024 14:43:44 +0200 Subject: [PATCH] Add custom panic handler Sadly, it doesn't seem to be called on segfaults, which means that will still output garbage. I could install a custom segfault handler, but not sure that's worth the effort. --- src/main.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.zig b/src/main.zig index 69c47f5..812f4e5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -61,6 +61,14 @@ pub const allocator = std.mem.Allocator{ }; +// Custom panic impl to reset the terminal before spewing out an error message. +pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn { + @setCold(true); + ui.deinit(); + std.debug.panicImpl(error_return_trace, ret_addr orelse @returnAddress(), msg); +} + + pub const config = struct { pub const SortCol = enum { name, blocks, size, items, mtime }; pub const SortOrder = enum { asc, desc };