summaryrefslogtreecommitdiffstats
path: root/src/commands/delete_files.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-22 12:59:13 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-22 13:32:02 -0500
commit03594099dafb4cda04e50f087df61cf76e2034d0 (patch)
tree724d31c9b1d31d122d1862141fdc9391891821e4 /src/commands/delete_files.rs
parentb3ed647b033c079a614e7a9ff5bb88da14dd99b4 (diff)
move the majority of rendering into its own widget: TuiView
- textfield is now a widget as well - reduced code duplication with TuiView - add backtab support - add a message queue for notifications
Diffstat (limited to 'src/commands/delete_files.rs')
-rw-r--r--src/commands/delete_files.rs64
1 files changed, 51 insertions, 13 deletions
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index f1ce09d..2219283 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -1,6 +1,10 @@
use std::fs;
+use std::io::{self, Write};
use std::path;
+use termion::clear;
+use termion::cursor::Goto;
+
use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
@@ -45,6 +49,21 @@ impl DeleteFiles {
));
}
+ let frame = backend.terminal.get_frame();
+ let f_size = frame.size();
+
+ let termion_terminal = backend.terminal.backend_mut();
+
+ write!(
+ termion_terminal,
+ "{}Delete {} files? (y/N){}",
+ Goto(1, f_size.height),
+ paths.len(),
+ clear::AfterCursor
+ );
+
+ io::stdout().flush().ok();
+
let mut ch = termion::event::Key::Char('n');
while let Ok(evt) = context.events.next() {
match evt {
@@ -52,19 +71,7 @@ impl DeleteFiles {
if key == termion::event::Key::Char('y')
|| key == termion::event::Key::Char('\n')
{
- if paths.len() > 1 {
- while let Ok(evt) = context.events.next() {
- match evt {
- Event::Input(key) => {
- ch = key;
- break;
- }
- _ => {}
- }
- }
- } else {
- ch = termion::event::Key::Char('y');
- }
+ ch = termion::event::Key::Char('y');
}
break;
}
@@ -73,9 +80,40 @@ impl DeleteFiles {
}
if ch == termion::event::Key::Char('y') {
+ if paths.len() > 1 {
+ write!(
+ termion_terminal,
+ "{}Are you sure? (Y/n){}",
+ Goto(1, f_size.height),
+ clear::AfterCursor
+ );
+
+ io::stdout().flush().ok();
+
+ while let Ok(evt) = context.events.next() {
+ match evt {
+ Event::Input(key) => {
+ ch = key;
+ break;
+ }
+ _ => {}
+ }
+ }
+ } else {
+ ch = termion::event::Key::Char('y');
+ }
+ }
+
+ if ch == termion::event::Key::Char('y') {
Self::remove_files(&paths)?;
ReloadDirList::reload(context.curr_tab_index, context)?;
}
+ write!(
+ termion_terminal,
+ "{}{}",
+ Goto(1, f_size.height),
+ clear::AfterCursor
+ );
Ok(())
}
}