Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 175de56

Browse files
committed
exit the program directly to avoid latency
1 parent 821a456 commit 175de56

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/interactive/app/eventloop.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ use dua::{
88
WalkOptions, WalkResult,
99
};
1010
use failure::Error;
11-
use std::{collections::BTreeMap, io, path::PathBuf};
11+
use std::{
12+
collections::BTreeMap,
13+
io,
14+
path::PathBuf,
15+
io::Write
16+
};
1217
use termion::event::Key;
1318
use tui::backend::Backend;
1419
use tui_react::Terminal;
@@ -72,7 +77,7 @@ impl TerminalApp {
7277
}
7378
pub fn process_events<B>(
7479
&mut self,
75-
terminal: &mut Terminal<B>,
80+
mut terminal: Terminal<B>,
7681
keys: impl Iterator<Item = Result<Key, io::Error>>,
7782
) -> Result<WalkResult, Error>
7883
where
@@ -81,7 +86,7 @@ impl TerminalApp {
8186
use termion::event::Key::*;
8287
use FocussedPane::*;
8388

84-
self.draw(terminal)?;
89+
self.draw(&mut terminal)?;
8590
for key in keys.filter_map(Result::ok) {
8691
self.update_message();
8792
match key {
@@ -91,7 +96,13 @@ impl TerminalApp {
9196
}
9297
Ctrl('c') => break,
9398
Char('q') | Esc => match self.state.focussed {
94-
Main => break,
99+
Main => {
100+
drop(terminal);
101+
io::stdout().flush().ok();
102+
// Exit 'quickly' to avoid having to wait for all memory to be freed by us.
103+
// Let the OS do it - we have nothing to lose, literally.
104+
std::process::exit(0);
105+
},
95106
Mark => self.state.focussed = Main,
96107
Help => {
97108
self.state.focussed = Main;
@@ -102,7 +113,7 @@ impl TerminalApp {
102113
}
103114

104115
match self.state.focussed {
105-
FocussedPane::Mark => self.dispatch_to_mark_pane(key, terminal),
116+
FocussedPane::Mark => self.dispatch_to_mark_pane(key, &mut terminal),
106117
FocussedPane::Help => {
107118
self.window.help_pane.as_mut().expect("help pane").key(key);
108119
}
@@ -121,7 +132,7 @@ impl TerminalApp {
121132
_ => {}
122133
},
123134
};
124-
self.draw(terminal)?;
135+
self.draw(&mut terminal)?;
125136
}
126137
Ok(WalkResult {
127138
num_errors: self.traversal.io_errors,

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn run() -> Result<(), Error> {
4444
Terminal::new(backend)?
4545
};
4646
let mut app = TerminalApp::initialize(&mut terminal, walk_options, paths_from(input)?)?;
47-
let res = app.process_events(&mut terminal, io::stdin().keys())?;
47+
let res = app.process_events(terminal, io::stdin().keys())?;
4848
io::stdout().flush().ok();
4949
res
5050
}

0 commit comments

Comments
 (0)