summaryrefslogtreecommitdiffstats
path: root/src/commands
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-08-06 14:02:51 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-08-06 14:02:51 -0400
commite0bbe7f3890ee66acfc83357720c9bfabf782c39 (patch)
tree5cbffcecf97b9db516448cce5614d5aebcdb6a03 /src/commands
parentc176412f865c14f90a2392e93421f0523ae3b11b (diff)
make usercache persistent
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/mod.rs12
-rw-r--r--src/commands/open_file.rs28
2 files changed, 18 insertions, 22 deletions
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index d94e1a0..ad60802 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -55,12 +55,6 @@ pub enum CommandKeybind {
CompositeKeybind(JoshutoCommandMapping),
}
-pub trait JoshutoRunnable {
- fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()>;
-}
-
-pub trait JoshutoCommand: JoshutoRunnable + std::fmt::Display + std::fmt::Debug {}
-
impl std::fmt::Display for CommandKeybind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
@@ -70,6 +64,12 @@ impl std::fmt::Display for CommandKeybind {
}
}
+pub trait JoshutoRunnable {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()>;
+}
+
+pub trait JoshutoCommand: JoshutoRunnable + std::fmt::Display + std::fmt::Debug {}
+
pub fn from_args(command: String, args: Vec<String>) -> JoshutoResult<Box<JoshutoCommand>> {
match command.as_str() {
"bulk_rename" => Ok(Box::new(self::BulkRename::new())),
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index 5eb8493..8b60a2f 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -68,7 +68,7 @@ impl OpenFile {
}
let mimetype_options = Self::get_options(&paths[0]);
if !mimetype_options.is_empty() {
- mimetype_options[0].execute_with(&paths);
+ mimetype_options[0].execute_with(&paths)?;
} else if context.config_t.xdg_open {
ncurses::savetty();
ncurses::endwin();
@@ -76,7 +76,7 @@ impl OpenFile {
ncurses::resetty();
ncurses::refresh();
} else {
- OpenFileWith::open_with(&paths);
+ OpenFileWith::open_with(&paths)?;
}
let curr_tab = &mut context.tabs[context.curr_tab_index];
if curr_tab.curr_list.need_update() {
@@ -137,7 +137,7 @@ impl OpenFileWith {
"open_file_with"
}
- pub fn open_with(paths: &[&PathBuf]) -> JoshutoResult<()> {
+ pub fn open_with(paths: &[&PathBuf]) -> std::io::Result<()> {
const PROMPT: &str = ":open_with ";
let mimetype_options: Vec<&JoshutoMimetypeEntry> = OpenFile::get_options(&paths[0]);
@@ -174,27 +174,23 @@ impl OpenFileWith {
Some(user_input) => match user_input.parse::<usize>() {
Ok(n) => {
if n < mimetype_options.len() {
- mimetype_options[n].execute_with(paths);
- Ok(())
+ mimetype_options[n].execute_with(paths)
} else {
- Err(JoshutoError::new(
- JoshutoErrorKind::IOInvalidData,
+ let err = std::io::Error::new(
+ std::io::ErrorKind::InvalidData,
"option does not exist".to_owned(),
- ))
+ );
+ Err(err)
}
}
Err(_) => {
let mut args_iter = user_input.split_whitespace();
match args_iter.next() {
- Some(s) => {
- let command = String::from(s);
- JoshutoMimetypeEntry::new(command)
+ Some(s) => JoshutoMimetypeEntry::new(s.to_owned())
.add_args(args_iter)
- .execute_with(paths);
- }
- None => {}
+ .execute_with(paths),
+ None => Ok(()),
}
- Ok(())
}
},
}
@@ -222,7 +218,7 @@ impl JoshutoRunnable for OpenFileWith {
Some(_) => {}
}
let paths = curr_list.get_selected_paths();
- Self::open_with(&paths);
+ Self::open_with(&paths)?;
Ok(())
}
}