summaryrefslogtreecommitdiffstats
path: root/src/commands
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
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')
-rw-r--r--src/commands/change_directory.rs2
-rw-r--r--src/commands/command_line.rs6
-rw-r--r--src/commands/cursor_move.rs16
-rw-r--r--src/commands/delete_files.rs64
-rw-r--r--src/commands/open_file.rs2
-rw-r--r--src/commands/reload_dir.rs6
-rw-r--r--src/commands/set_mode.rs2
-rw-r--r--src/commands/show_hidden.rs2
8 files changed, 65 insertions, 35 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 1897b90..ac97d59 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -53,7 +53,7 @@ impl std::fmt::Display for ChangeDirectory {
}
impl JoshutoRunnable for ChangeDirectory {
- fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
Self::change_directories(&self.path, context)?;
LoadChild::load_child(context)?;
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index 5795e5d..a00f442 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -1,8 +1,8 @@
use crate::commands::{self, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
+use crate::ui::widgets::TuiTextField;
use crate::ui::TuiBackend;
-use crate::util::textfield::TextField;
#[derive(Clone, Debug)]
pub struct CommandLine {
@@ -23,8 +23,8 @@ impl CommandLine {
context: &mut JoshutoContext,
backend: &mut TuiBackend,
) -> JoshutoResult<()> {
- let mut textfield = TextField::new(backend, &context.events);
- let user_input: Option<String> = textfield.readline();
+ // let mut textfield = TuiTextField::new(backend, &context.events);
+ let user_input: Option<String> = None; // textfield.readline();
if let Some(s) = user_input {
let trimmed = s.trim_start();
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index 03d9908..36ba233 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -218,13 +218,9 @@ impl std::fmt::Display for CursorMoveHome {
impl JoshutoRunnable for CursorMoveHome {
fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
- let movement: Option<usize> = match context
- .curr_tab_ref()
- .curr_list_ref() {
+ let movement: Option<usize> = match context.curr_tab_ref().curr_list_ref() {
Some(curr_list) => {
- let len = curr_list
- .contents
- .len();
+ let len = curr_list.contents.len();
if len == 0 {
None
} else {
@@ -263,13 +259,9 @@ impl std::fmt::Display for CursorMoveEnd {
impl JoshutoRunnable for CursorMoveEnd {
fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
- let movement: Option<usize> = match context
- .curr_tab_ref()
- .curr_list_ref() {
+ let movement: Option<usize> = match context.curr_tab_ref().curr_list_ref() {
Some(curr_list) => {
- let len = curr_list
- .contents
- .len();
+ let len = curr_list.contents.len();
if len == 0 {
None
} else {
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(())
}
}
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index 4f29432..f41ee7e 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -5,9 +5,9 @@ use crate::config::mimetype::JoshutoMimetypeEntry;
use crate::context::JoshutoContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::history::DirectoryHistory;
+use crate::ui::widgets::TuiTextField;
use crate::ui::TuiBackend;
use crate::util::load_child::LoadChild;
-use crate::util::textfield::TextField;
use crate::MIMETYPE_T;
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs
index eef3a3f..88cfc46 100644
--- a/src/commands/reload_dir.rs
+++ b/src/commands/reload_dir.rs
@@ -20,15 +20,15 @@ impl ReloadDirList {
match curr_tab.curr_list_mut() {
Some(curr_list) => curr_list.reload_contents(sort_option)?,
- None => {},
+ None => {}
}
match curr_tab.parent_list_mut() {
Some(curr_list) => curr_list.reload_contents(sort_option)?,
- None => {},
+ None => {}
}
match curr_tab.child_list_mut() {
Some(curr_list) => curr_list.reload_contents(sort_option)?,
- None => {},
+ None => {}
}
Ok(())
diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs
index 07f6d37..8a974e9 100644
--- a/src/commands/set_mode.rs
+++ b/src/commands/set_mode.rs
@@ -2,9 +2,9 @@ use crate::commands::{CursorMoveDown, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::fs::JoshutoDirEntry;
+use crate::ui::widgets::TuiTextField;
use crate::ui::TuiBackend;
use crate::unix;
-use crate::util::textfield::TextField;
#[derive(Clone, Debug)]
pub struct SetMode;
diff --git a/src/commands/show_hidden.rs b/src/commands/show_hidden.rs
index 63ac4bf..0a22c53 100644
--- a/src/commands/show_hidden.rs
+++ b/src/commands/show_hidden.rs
@@ -22,7 +22,7 @@ impl ToggleHiddenFiles {
tab.history.depreciate_all_entries();
match tab.curr_list_mut() {
Some(s) => s.depreciate(),
- None => {},
+ None => {}
}
}
}