From 13e5695ea499d84f508748d120d282f55cb288f5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 29 Mar 2020 17:24:36 +0800 Subject: =?UTF-8?q?Surprisingly=20complicated=20to=20get=20back=20to=20nor?= =?UTF-8?q?mal=20TTY=20without=20dropping=20the=20terminal=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem is that undoing the RAW mode is not possible with the current implementation. We can't just force it off it seems. --- src/interactive/app/eventloop.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/interactive') diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index 4baaa7f..d109bad 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -9,9 +9,7 @@ use dua::{ }; use failure::Error; use std::{collections::BTreeMap, io, io::Write, path::PathBuf}; -use termion::event::Key; -use termion::input::TermRead; -use termion::screen::ToMainScreen; +use termion::{event::Key, input::TermRead, raw::IntoRawMode, screen::ToMainScreen}; use tui::backend::Backend; use tui_react::Terminal; @@ -72,8 +70,14 @@ impl AppState { use termion::event::Key::*; use FocussedPane::*; - fn exit_now() -> ! { + fn exit_now(terminal: &mut Terminal) -> ! { + terminal.show_cursor().ok(); write!(io::stdout(), "{}", ToMainScreen).ok(); + io::stdout() + .into_raw_mode() + .expect("TTY") + .suspend_raw_mode() + .ok(); io::stdout().flush().ok(); // Exit 'quickly' to avoid having to wait for all memory to be freed by us. // Let the OS do it - we have nothing to lose, literally. @@ -88,9 +92,9 @@ impl AppState { Char('\t') => { self.cycle_focus(window); } - Ctrl('c') => exit_now(), + Ctrl('c') => exit_now(terminal), Char('q') | Esc => match self.focussed { - Main => exit_now(), + Main => exit_now(terminal), Mark => self.focussed = Main, Help => { self.focussed = Main; -- cgit v1.2.3