summaryrefslogtreecommitdiffstats
path: root/src/commands
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-18 22:55:09 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-03-18 22:55:09 -0400
commit06b2d7730d10240b471e859c7988ed219aa4c590 (patch)
treef5dcca189bb2d79c4def09540eec73cdb832c6b8 /src/commands
parentf3081669e488c54ab4fcae2829ea2f58f082c6e7 (diff)
remove cursormovestub and add rudimentary sort command
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/cursor_move.rs36
-rw-r--r--src/commands/delete_files.rs6
-rw-r--r--src/commands/file_ops/paste_copy.rs7
-rw-r--r--src/commands/file_ops/paste_cut.rs7
-rw-r--r--src/commands/mod.rs23
-rw-r--r--src/commands/reload_dir.rs5
-rw-r--r--src/commands/rename_file.rs5
-rw-r--r--src/commands/sort.rs39
-rw-r--r--src/commands/tab_operations.rs5
9 files changed, 80 insertions, 53 deletions
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index ba536bb..a19c264 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -30,46 +30,12 @@ pub fn cursor_move(new_index: usize, context: &mut JoshutoContext) {
if path.is_dir() {
curr_tab
.history
- .create_or_update(path.as_path(), &context.config_t.sort_option);
+ .create_or_soft_update(path.as_path(), &context.config_t.sort_option);
}
}
}
#[derive(Clone, Debug)]
-pub struct CursorMoveStub {}
-
-impl CursorMoveStub {
- pub fn new() -> Self {
- Self {}
- }
- pub const fn command() -> &'static str {
- "cursor_move_stub"
- }
-}
-
-impl JoshutoCommand for CursorMoveStub {}
-
-impl std::fmt::Display for CursorMoveStub {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(f, "{}", Self::command())
- }
-}
-
-impl JoshutoRunnable for CursorMoveStub {
- fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
- let new_index = match context.curr_tab_ref().curr_list_ref() {
- Some(curr_list) => curr_list.index,
- None => None,
- };
-
- if let Some(s) = new_index {
- cursor_move(s, context)
- }
- Ok(())
- }
-}
-
-#[derive(Clone, Debug)]
pub struct CursorMoveDown {
movement: usize,
}
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 9e302b0..628f324 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -3,12 +3,12 @@ use std::path;
use termion::event::Key;
-use crate::commands::{CursorMoveStub, JoshutoCommand, JoshutoRunnable, ReloadDirList};
+use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::ui::TuiBackend;
-
use crate::ui::widgets::TuiPrompt;
+use crate::util::load_child::LoadChild;
#[derive(Clone, Debug)]
pub struct DeleteFiles;
@@ -90,7 +90,7 @@ impl std::fmt::Display for DeleteFiles {
impl JoshutoRunnable for DeleteFiles {
fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
Self::delete_files(context, backend)?;
- CursorMoveStub::new().execute(context, backend)?;
+ LoadChild::load_child(context)?;
Ok(())
}
}
diff --git a/src/commands/file_ops/paste_copy.rs b/src/commands/file_ops/paste_copy.rs
index b3234bf..46bafbc 100644
--- a/src/commands/file_ops/paste_copy.rs
+++ b/src/commands/file_ops/paste_copy.rs
@@ -50,8 +50,8 @@ pub fn paste_copy(
let (tx_start, rx_start) = mpsc::channel();
let (tx, rx) = mpsc::channel();
- let handle: thread::JoinHandle<std::io::Result<u64>> = thread::spawn(move || {
- match rx_start.recv() {
+ let handle: thread::JoinHandle<std::io::Result<u64>> =
+ thread::spawn(move || match rx_start.recv() {
Ok(_) => {
let mut total = 0;
for path in paths {
@@ -61,8 +61,7 @@ pub fn paste_copy(
Ok(total)
}
Err(_) => Ok(0),
- }
- });
+ });
let thread = IOWorkerThread {
src,
diff --git a/src/commands/file_ops/paste_cut.rs b/src/commands/file_ops/paste_cut.rs
index 5b6683b..4fa171d 100644
--- a/src/commands/file_ops/paste_cut.rs
+++ b/src/commands/file_ops/paste_cut.rs
@@ -64,8 +64,8 @@ pub fn paste_cut(
let (tx_start, rx_start) = mpsc::channel();
let (tx, rx) = mpsc::channel();
- let handle: thread::JoinHandle<std::io::Result<u64>> = thread::spawn(move || {
- match rx_start.recv() {
+ let handle: thread::JoinHandle<std::io::Result<u64>> =
+ thread::spawn(move || match rx_start.recv() {
Ok(_) => {
let mut total = 0;
for path in paths {
@@ -75,8 +75,7 @@ pub fn paste_cut(
Ok(total)
}
Err(_) => Ok(0),
- }
- });
+ });
let thread = IOWorkerThread {
src,
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index d511a52..b322d49 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -14,6 +14,7 @@ mod search;
mod selection;
mod set_mode;
mod show_hidden;
+mod sort;
mod tab_operations;
mod tab_switch;
@@ -22,7 +23,7 @@ pub use self::change_directory::ChangeDirectory;
pub use self::command_line::CommandLine;
pub use self::cursor_move::{
CursorMoveDown, CursorMoveEnd, CursorMoveHome, CursorMovePageDown, CursorMovePageUp,
- CursorMoveStub, CursorMoveUp,
+ CursorMoveUp,
};
pub use self::delete_files::DeleteFiles;
pub use self::file_ops::{CopyFiles, CutFiles, PasteFiles};
@@ -37,6 +38,7 @@ pub use self::search::{Search, SearchNext, SearchPrev};
pub use self::selection::SelectFiles;
pub use self::set_mode::SetMode;
pub use self::show_hidden::ToggleHiddenFiles;
+pub use self::sort::Sort;
pub use self::tab_operations::{CloseTab, NewTab};
pub use self::tab_switch::TabSwitch;
@@ -46,6 +48,7 @@ use crate::config::JoshutoCommandMapping;
use crate::context::JoshutoContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::io::Options;
+use crate::sort::SortType;
use crate::ui::TuiBackend;
use crate::HOME_DIR;
@@ -214,6 +217,24 @@ pub fn from_args(command: String, args: Vec<String>) -> JoshutoResult<Box<dyn Jo
Ok(Box::new(self::SelectFiles::new(toggle, all)))
}
"set_mode" => Ok(Box::new(self::SetMode::new())),
+ "sort" => {
+ if args.len() == 1 {
+ match args[0].as_str() {
+ "lexical" => Ok(Box::new(self::Sort::new(SortType::Lexical))),
+ "mtime" => Ok(Box::new(self::Sort::new(SortType::Mtime))),
+ "natural" => Ok(Box::new(self::Sort::new(SortType::Natural))),
+ a => Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("sort: Unknown option {}", a),
+ )),
+ }
+ } else {
+ Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("sort: Expected 1, got {}", args.len()),
+ ))
+ }
+ }
"tab_switch" => {
if args.len() == 1 {
match args[0].parse::<i32>() {
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs
index 2951e9f..a5ef752 100644
--- a/src/commands/reload_dir.rs
+++ b/src/commands/reload_dir.rs
@@ -1,7 +1,8 @@
-use crate::commands::{CursorMoveStub, JoshutoCommand, JoshutoRunnable};
+use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::ui::TuiBackend;
+use crate::util::load_child::LoadChild;
#[derive(Clone, Debug)]
pub struct ReloadDirList;
@@ -43,7 +44,7 @@ impl std::fmt::Display for ReloadDirList {
impl JoshutoRunnable for ReloadDirList {
fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
Self::reload(context.curr_tab_index, context)?;
- CursorMoveStub::new().execute(context, backend)?;
+ LoadChild::load_child(context)?;
Ok(())
}
}
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index 0bab5e6..a36c86c 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -1,9 +1,10 @@
use std::path;
-use crate::commands::{CommandLine, CursorMoveStub, JoshutoCommand, JoshutoRunnable};
+use crate::commands::{CommandLine, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::ui::TuiBackend;
+use crate::util::load_child::LoadChild;
#[derive(Clone, Debug)]
pub struct RenameFile {
@@ -59,7 +60,7 @@ impl JoshutoRunnable for RenameFile {
if let Some(path) = path {
self.rename_file(&path, context)?;
}
- CursorMoveStub::new().execute(context, backend)?;
+ LoadChild::load_child(context)?;
Ok(())
}
}
diff --git a/src/commands/sort.rs b/src/commands/sort.rs
new file mode 100644
index 0000000..935e7fd
--- /dev/null
+++ b/src/commands/sort.rs
@@ -0,0 +1,39 @@
+use std::path;
+
+use crate::commands::{JoshutoCommand, JoshutoRunnable};
+use crate::context::JoshutoContext;
+use crate::error::JoshutoResult;
+use crate::ui::TuiBackend;
+
+use crate::sort::SortType;
+
+use crate::HOME_DIR;
+
+#[derive(Clone, Debug)]
+pub struct Sort {
+ sort_method: SortType,
+}
+
+impl Sort {
+ pub fn new(sort_method: SortType) -> Self {
+ Self { sort_method }
+ }
+ pub const fn command() -> &'static str {
+ "sort"
+ }
+}
+
+impl JoshutoCommand for Sort {}
+
+impl std::fmt::Display for Sort {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ f.write_str(Self::command())
+ }
+}
+
+impl JoshutoRunnable for Sort {
+ fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> {
+ context.config_t.sort_option.sort_method = self.sort_method;
+ Ok(())
+ }
+}
diff --git a/src/commands/tab_operations.rs b/src/commands/tab_operations.rs
index 6c62d09..52c03ef 100644
--- a/src/commands/tab_operations.rs
+++ b/src/commands/tab_operations.rs
@@ -1,10 +1,11 @@
use std::path;
-use crate::commands::{CursorMoveStub, JoshutoCommand, JoshutoRunnable, Quit, TabSwitch};
+use crate::commands::{JoshutoCommand, JoshutoRunnable, Quit, TabSwitch};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::tab::JoshutoTab;
use crate::ui::TuiBackend;
+use crate::util::load_child::LoadChild;
use crate::HOME_DIR;
@@ -30,7 +31,7 @@ impl NewTab {
context.tabs.push(tab);
context.curr_tab_index = context.tabs.len() - 1;
TabSwitch::tab_switch(context.curr_tab_index, context)?;
- CursorMoveStub::new().execute(context, backend)?;
+ LoadChild::load_child(context)?;
Ok(())
}
}