feat(vaxis): reset terminal state on panic with a custom panic handler
This commit is contained in:
parent
49ad54d60c
commit
dc21e7f6ac
2 changed files with 17 additions and 2 deletions
|
@ -15,10 +15,15 @@ pub const application_name = "flow";
|
||||||
pub const application_logo = " ";
|
pub const application_logo = " ";
|
||||||
|
|
||||||
pub const std_options = .{
|
pub const std_options = .{
|
||||||
.log_level = .debug,
|
// .log_level = if (builtin.mode == .Debug) .debug else .warn,
|
||||||
|
.log_level = if (builtin.mode == .Debug) .info else .warn,
|
||||||
.logFn = log.std_log_function,
|
.logFn = log.std_log_function,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderer = @import("renderer");
|
||||||
|
|
||||||
|
pub const panic = if (@hasDecl(renderer, "panic")) renderer.panic else std.builtin.default_panic;
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
const params = comptime clap.parseParamsComptime(
|
const params = comptime clap.parseParamsComptime(
|
||||||
\\-h, --help Display this help and exit.
|
\\-h, --help Display this help and exit.
|
||||||
|
|
|
@ -69,14 +69,24 @@ pub fn init(a: std.mem.Allocator, handler_ctx: *anyopaque, no_alternate: bool) !
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
|
panic_cleanup_tty = null;
|
||||||
self.vx.deinit(self.a);
|
self.vx.deinit(self.a);
|
||||||
self.bracketed_paste_buffer.deinit();
|
self.bracketed_paste_buffer.deinit();
|
||||||
self.input_buffer.deinit();
|
self.input_buffer.deinit();
|
||||||
self.event_buffer.deinit();
|
self.event_buffer.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var panic_cleanup_tty: ?*vaxis.Tty = null;
|
||||||
|
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
|
||||||
|
if (panic_cleanup_tty) |tty| tty.deinit();
|
||||||
|
return std.builtin.default_panic(msg, error_return_trace, ret_addr);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(self: *Self) !void {
|
pub fn run(self: *Self) !void {
|
||||||
if (self.vx.tty == null) self.vx.tty = try vaxis.Tty.init();
|
if (self.vx.tty == null) {
|
||||||
|
self.vx.tty = try vaxis.Tty.init();
|
||||||
|
panic_cleanup_tty = &(self.vx.tty.?);
|
||||||
|
}
|
||||||
if (!self.no_alternate) try self.vx.enterAltScreen();
|
if (!self.no_alternate) try self.vx.enterAltScreen();
|
||||||
try self.vx.queryTerminalSend();
|
try self.vx.queryTerminalSend();
|
||||||
const ws = try vaxis.Tty.getWinsize(self.input_fd_blocking());
|
const ws = try vaxis.Tty.getWinsize(self.input_fd_blocking());
|
||||||
|
|
Loading…
Add table
Reference in a new issue