diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-03-29 17:29:23 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-03-29 17:29:23 +0800 |
commit | 437eb41def66eedf4614902e42eb1d265967093c (patch) | |
tree | 50d5282d5898211a06b701aa11e613276a418da8 /src | |
parent | 13e5695ea499d84f508748d120d282f55cb288f5 (diff) |
Properly shutdown dua with quick-exit - solves all problems
Interesting, how unfit code is naturally hard to use, and fit codeā¦
just fits :D
Diffstat (limited to 'src')
-rw-r--r-- | src/interactive/app/eventloop.rs | 22 | ||||
-rw-r--r-- | src/main.rs | 7 |
2 files changed, 9 insertions, 20 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index d109bad..081a47e 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -8,8 +8,8 @@ use dua::{ WalkOptions, WalkResult, }; use failure::Error; -use std::{collections::BTreeMap, io, io::Write, path::PathBuf}; -use termion::{event::Key, input::TermRead, raw::IntoRawMode, screen::ToMainScreen}; +use std::{collections::BTreeMap, io, path::PathBuf}; +use termion::{event::Key, input::TermRead}; use tui::backend::Backend; use tui_react::Terminal; @@ -70,20 +70,6 @@ impl AppState { use termion::event::Key::*; use FocussedPane::*; - fn exit_now<B: Backend>(terminal: &mut Terminal<B>) -> ! { - 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. - std::process::exit(0); - } - self.draw(window, traversal, display.clone(), terminal)?; for key in keys.filter_map(Result::ok) { self.reset_message(); @@ -92,9 +78,9 @@ impl AppState { Char('\t') => { self.cycle_focus(window); } - Ctrl('c') => exit_now(terminal), + Ctrl('c') => break, Char('q') | Esc => match self.focussed { - Main => exit_now(terminal), + Main => break, Mark => self.focussed = Main, Help => { self.focussed = Main; diff --git a/src/main.rs b/src/main.rs index 9b0faad..a4a2227 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,9 +49,12 @@ fn run() -> Result<(), Error> { paths_from(input)?, Interaction::Full, )?; - let res = app.process_events(&mut terminal, io::stdin().keys())?; + app.process_events(&mut terminal, io::stdin().keys())?; + drop(terminal); io::stdout().flush().ok(); - res + // 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. + std::process::exit(0); } Some(Aggregate { input, |