summaryrefslogtreecommitdiffstats
path: root/src/commands/delete_files.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-09 13:22:58 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-09 13:23:02 -0500
commit5b0f74d385b26a14470ce79dc111a3a80af90a7b (patch)
tree6de7c0df3adf789934b8396a8ad80a2cc393fe83 /src/commands/delete_files.rs
parentbecbb90b2f22d58c98693d653f55ba604bb03f75 (diff)
update delete file prompt to use new input thread
Diffstat (limited to 'src/commands/delete_files.rs')
-rw-r--r--src/commands/delete_files.rs40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index c726dd4..8233ce2 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -5,6 +5,7 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::ui;
+use crate::util::event::Event;
use crate::window::JoshutoView;
use crate::KEYMAP_T;
@@ -45,13 +46,40 @@ impl DeleteFiles {
"no files selected",
));
}
- if paths.len() > 1 {
- ui::wprint_msg(&view.bot_win, "Are you sure? (y/N)");
- } else {
+
+ let mut ch = termion::event::Key::Char('n');
+ while let Ok(evt) = context.events.next() {
+ match evt {
+ Event::Input(key) => {
+ if key == termion::event::Key::Char('y') ||
+ key == termion::event::Key::Char('\n') {
+ if paths.len() > 1 {
+ ui::wprint_msg(&view.bot_win, "Are you sure? (y/N)");
+ ncurses::doupdate();
+ while let Ok(evt) = context.events.next() {
+ match evt {
+ Event::Input(key) => {
+ ch = key;
+ break;
+ }
+ _ => {}
+ }
+ }
+ } else {
+ ch = termion::event::Key::Char('y');
+ }
+ }
+ break;
+ }
+ _ => {}
+ }
+ }
+
+ if ch == termion::event::Key::Char('y') {
+ Self::remove_files(&paths)?;
+ ui::wprint_msg(&view.bot_win, "Deleted files");
+ ReloadDirList::reload(context.curr_tab_index, context)?;
}
- Self::remove_files(&paths)?;
- ui::wprint_msg(&view.bot_win, "Deleted files");
- ReloadDirList::reload(context.curr_tab_index, context)?;
Ok(())
}
}