From 175de56ebe0aff01f7e67de9862d98ba0970feea Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 14 Mar 2020 21:56:05 +0800 Subject: exit the program directly to avoid latency --- src/interactive/app/eventloop.rs | 23 +++++++++++++++++------ src/main.rs | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index f47da29..c166697 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -8,7 +8,12 @@ use dua::{ WalkOptions, WalkResult, }; use failure::Error; -use std::{collections::BTreeMap, io, path::PathBuf}; +use std::{ + collections::BTreeMap, + io, + path::PathBuf, + io::Write +}; use termion::event::Key; use tui::backend::Backend; use tui_react::Terminal; @@ -72,7 +77,7 @@ impl TerminalApp { } pub fn process_events( &mut self, - terminal: &mut Terminal, + mut terminal: Terminal, keys: impl Iterator>, ) -> Result where @@ -81,7 +86,7 @@ impl TerminalApp { use termion::event::Key::*; use FocussedPane::*; - self.draw(terminal)?; + self.draw(&mut terminal)?; for key in keys.filter_map(Result::ok) { self.update_message(); match key { @@ -91,7 +96,13 @@ impl TerminalApp { } Ctrl('c') => break, Char('q') | Esc => match self.state.focussed { - Main => break, + Main => { + drop(terminal); + 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); + }, Mark => self.state.focussed = Main, Help => { self.state.focussed = Main; @@ -102,7 +113,7 @@ impl TerminalApp { } match self.state.focussed { - FocussedPane::Mark => self.dispatch_to_mark_pane(key, terminal), + FocussedPane::Mark => self.dispatch_to_mark_pane(key, &mut terminal), FocussedPane::Help => { self.window.help_pane.as_mut().expect("help pane").key(key); } @@ -121,7 +132,7 @@ impl TerminalApp { _ => {} }, }; - self.draw(terminal)?; + self.draw(&mut terminal)?; } Ok(WalkResult { num_errors: self.traversal.io_errors, diff --git a/src/main.rs b/src/main.rs index 22e47df..cfe6228 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,7 @@ fn run() -> Result<(), Error> { Terminal::new(backend)? }; let mut app = TerminalApp::initialize(&mut terminal, walk_options, paths_from(input)?)?; - let res = app.process_events(&mut terminal, io::stdin().keys())?; + let res = app.process_events(terminal, io::stdin().keys())?; io::stdout().flush().ok(); res } -- cgit v1.2.3