From b9112da4b2e5e03646911ac438c4519417764c0b Mon Sep 17 00:00:00 2001 From: Ideflop Date: Mon, 29 Jan 2024 22:18:05 +0100 Subject: [PATCH] more: Disable raw mode before exiting if a panic occurs --- src/uu/more/src/more.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index f651a033b..7df717218 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -8,6 +8,7 @@ use std::{ fs::File, io::{stdin, stdout, BufReader, IsTerminal, Read, Stdout, Write}, + panic::set_hook, path::Path, time::Duration, }; @@ -87,6 +88,13 @@ impl Options { #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { + // Disable raw mode before exiting if a panic occurs + set_hook(Box::new(|panic_info| { + terminal::disable_raw_mode().unwrap(); + print!("\r"); + println!("{panic_info}"); + })); + let matches = match uu_app().try_get_matches_from(args) { Ok(m) => m, Err(e) => return Err(e.into()),