Skip to content

Commit

Permalink
Properly shutdown dua with quick-exit - solves all problems
Browse files Browse the repository at this point in the history
Interesting, how unfit code is naturally hard to use, and fit code…
just fits :D
  • Loading branch information
Byron committed Mar 29, 2020
1 parent 13e5695 commit 437eb41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
22 changes: 4 additions & 18 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 437eb41

Please sign in to comment.