summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2020-03-14 21:56:05 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-03-14 21:56:05 +0800
commit175de56ebe0aff01f7e67de9862d98ba0970feea (patch)
tree56f877a796ba7ccb26ec9c1e225610757866521e
parent821a45642036597002db798238dc719849be6f56 (diff)
exit the program directly to avoid latency
-rw-r--r--src/interactive/app/eventloop.rs23
-rw-r--r--src/main.rs2
2 files changed, 18 insertions, 7 deletions
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<B>(
&mut self,
- terminal: &mut Terminal<B>,
+ mut terminal: Terminal<B>,
keys: impl Iterator<Item = Result<Key, io::Error>>,
) -> Result<WalkResult, Error>
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
}