summaryrefslogtreecommitdiffstats
path: root/src/interactive
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2020-03-29 17:24:36 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-03-29 17:24:36 +0800
commit13e5695ea499d84f508748d120d282f55cb288f5 (patch)
tree6fdf22306f4a5f098fc9f53d8c1bbbd3c34ec168 /src/interactive
parent0e25706db7e25d53678b23548eddf5809a789ab4 (diff)
Surprisingly complicated to get back to normal TTY without dropping the terminal…
Problem is that undoing the RAW mode is not possible with the current implementation. We can't just force it off it seems.
Diffstat (limited to 'src/interactive')
-rw-r--r--src/interactive/app/eventloop.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index 4baaa7f..d109bad 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -9,9 +9,7 @@ use dua::{
};
use failure::Error;
use std::{collections::BTreeMap, io, io::Write, path::PathBuf};
-use termion::event::Key;
-use termion::input::TermRead;
-use termion::screen::ToMainScreen;
+use termion::{event::Key, input::TermRead, raw::IntoRawMode, screen::ToMainScreen};
use tui::backend::Backend;
use tui_react::Terminal;
@@ -72,8 +70,14 @@ impl AppState {
use termion::event::Key::*;
use FocussedPane::*;
- fn exit_now() -> ! {
+ 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.
@@ -88,9 +92,9 @@ impl AppState {
Char('\t') => {
self.cycle_focus(window);
}
- Ctrl('c') => exit_now(),
+ Ctrl('c') => exit_now(terminal),
Char('q') | Esc => match self.focussed {
- Main => exit_now(),
+ Main => exit_now(terminal),
Mark => self.focussed = Main,
Help => {
self.focussed = Main;