From 91343a68461608efa9f45be75a7dcaece0fd65a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sat, 19 Sep 2020 11:57:22 +0900 Subject: [PATCH] Restore terminal mode on panics. --- helix-term/src/editor.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs index 397ce8df7..9b5cad515 100644 --- a/helix-term/src/editor.rs +++ b/helix-term/src/editor.rs @@ -376,6 +376,14 @@ impl Editor { execute!(stdout, terminal::EnterAlternateScreen)?; + // Exit the alternate screen and disable raw mode before panicking + let hook = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |info| { + execute!(std::io::stdout(), terminal::LeaveAlternateScreen); + disable_raw_mode(); + hook(info); + })); + self.event_loop().await; // reset cursor shape