summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/commands/change_directory.rs13
-rw-r--r--src/commands/command_line.rs24
-rw-r--r--src/commands/cursor_move.rs38
-rw-r--r--src/commands/delete_files.rs15
-rw-r--r--src/commands/file_operations.rs43
-rw-r--r--src/commands/mod.rs93
-rw-r--r--src/commands/new_directory.rs26
-rw-r--r--src/commands/open_file.rs12
-rw-r--r--src/commands/parent_directory.rs12
-rw-r--r--src/commands/quit.rs17
-rw-r--r--src/commands/reload_dir.rs22
-rw-r--r--src/commands/rename_file.rs29
-rw-r--r--src/commands/search.rs20
-rw-r--r--src/commands/selection.rs8
-rw-r--r--src/commands/set_mode.rs8
-rw-r--r--src/commands/show_hidden.rs8
-rw-r--r--src/commands/tab_operations.rs38
-rw-r--r--src/commands/tab_switch.rs10
-rw-r--r--src/config/keymap.rs2
-rw-r--r--src/config/mimetype.rs4
-rw-r--r--src/error.rs101
-rw-r--r--src/run.rs11
-rw-r--r--src/textfield.rs2
-rw-r--r--src/ui.rs15
24 files changed, 238 insertions, 333 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 27fa809..330c8b2 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -3,7 +3,7 @@ use std::path;
use crate::commands;
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::history::DirectoryHistory;
use crate::window::JoshutoView;
use commands::{JoshutoCommand, JoshutoRunnable};
@@ -58,15 +58,8 @@ impl std::fmt::Display for ChangeDirectory {
}
impl JoshutoRunnable for ChangeDirectory {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
- match Self::change_directory(&self.path, context, view) {
- Ok(_) => {}
- Err(e) => return Err(JoshutoError::IO(e)),
- }
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
+ Self::change_directory(&self.path, context, view)?;
ncurses::doupdate();
Ok(())
}
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index 036ad55..585ae23 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -1,6 +1,6 @@
use crate::commands::{self, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::textfield::JoshutoTextField;
use crate::ui;
use crate::window::JoshutoView;
@@ -19,11 +19,7 @@ impl CommandLine {
"console"
}
- pub fn readline(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ pub fn readline(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
const PROMPT: &str = ":";
let (term_rows, term_cols) = ui::getmaxyx();
let user_input: Option<String> = {
@@ -49,15 +45,9 @@ impl CommandLine {
Ok(wexp) => wexp.iter().collect(),
Err(_) => Vec::new(),
};
- match commands::from_args(command, &args) {
- Ok(s) => s.execute(context, view),
- Err(e) => Err(JoshutoError::Keymap(e)),
- }
+ commands::from_args(command, &args)?.execute(context, view)
}
- None => match commands::from_args(trimmed, &Vec::new()) {
- Ok(s) => s.execute(context, view),
- Err(e) => Err(JoshutoError::Keymap(e)),
- },
+ None => commands::from_args(trimmed, &Vec::new())?.execute(context, view),
}
} else {
Ok(())
@@ -74,11 +64,7 @@ impl std::fmt::Display for CommandLine {
}
impl JoshutoRunnable for CommandLine {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let res = self.readline(context, view);
ncurses::doupdate();
res
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index f401703..1ed3537 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -1,6 +1,6 @@
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::window::JoshutoView;
pub fn cursor_move(mut new_index: usize, context: &mut JoshutoContext, view: &JoshutoView) {
@@ -49,11 +49,7 @@ impl std::fmt::Display for CursorMoveDown {
}
impl JoshutoRunnable for CursorMoveDown {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let movement: Option<usize> = {
let curr_list = &mut context.curr_tab_mut().curr_list;
curr_list.index.map(|idx| idx + self.movement)
@@ -88,11 +84,7 @@ impl std::fmt::Display for CursorMoveUp {
}
impl JoshutoRunnable for CursorMoveUp {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let movement: Option<usize> = context.curr_tab_mut().curr_list.index.map(|idx| {
if idx > self.movement {
idx - self.movement
@@ -128,11 +120,7 @@ impl std::fmt::Display for CursorMovePageUp {
}
impl JoshutoRunnable for CursorMovePageUp {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let movement: Option<usize> = {
let curr_list = &mut context.curr_tab_mut().curr_list;
let half_page = view.mid_win.cols as usize / 2;
@@ -168,11 +156,7 @@ impl std::fmt::Display for CursorMovePageDown {
}
impl JoshutoRunnable for CursorMovePageDown {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let movement: Option<usize> = {
let curr_list = &mut context.curr_tab_mut().curr_list;
let dir_len = curr_list.contents.len();
@@ -214,11 +198,7 @@ impl std::fmt::Display for CursorMoveHome {
}
impl JoshutoRunnable for CursorMoveHome {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let movement: Option<usize> = {
let len = context.curr_tab_mut().curr_list.contents.len();
if len == 0 {
@@ -256,11 +236,7 @@ impl std::fmt::Display for CursorMoveEnd {
}
impl JoshutoRunnable for CursorMoveEnd {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let movement: Option<usize> = {
let len = context.curr_tab_mut().curr_list.contents.len();
if len == 0 {
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 045798f..ac66c9d 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -3,7 +3,7 @@ use std::path;
use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::ui;
use crate::window::JoshutoView;
@@ -74,18 +74,11 @@ impl std::fmt::Display for DeleteFiles {
}
impl JoshutoRunnable for DeleteFiles {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
- let res = Self::delete_files(context, view);
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
+ Self::delete_files(context, view)?;
let curr_tab = &mut context.tabs[context.curr_tab_index];
curr_tab.refresh(view, &context.config_t);
ncurses::doupdate();
- match res {
- Ok(_) => Ok(()),
- Err(e) => Err(JoshutoError::IO(e)),
- }
+ Ok(())
}
}
diff --git a/src/commands/file_operations.rs b/src/commands/file_operations.rs
index 441f615..9277f60 100644
--- a/src/commands/file_operations.rs
+++ b/src/commands/file_operations.rs
@@ -6,7 +6,7 @@ use std::time;
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::fs::{fs_extra_extra, JoshutoDirList};
use crate::window::JoshutoView;
@@ -87,16 +87,12 @@ impl std::fmt::Display for CutFiles {
}
impl JoshutoRunnable for CutFiles {
- fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> {
let curr_tab = context.curr_tab_ref();
- match LocalState::repopulated_selected_files(&curr_tab.curr_list) {
- Ok(_) => {
- LocalState::set_file_op(FileOp::Cut);
- LocalState::set_tab_src(context.curr_tab_index);
- Ok(())
- }
- Err(e) => Err(JoshutoError::IO(e)),
- }
+ LocalState::repopulated_selected_files(&curr_tab.curr_list)?;
+ LocalState::set_file_op(FileOp::Cut);
+ LocalState::set_tab_src(context.curr_tab_index);
+ Ok(())
}
}
@@ -121,16 +117,12 @@ impl std::fmt::Display for CopyFiles {
}
impl JoshutoRunnable for CopyFiles {
- fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> {
let curr_tab = context.curr_tab_ref();
- match LocalState::repopulated_selected_files(&curr_tab.curr_list) {
- Ok(_) => {
- LocalState::set_file_op(FileOp::Copy);
- LocalState::set_tab_src(context.curr_tab_index);
- Ok(())
- }
- Err(e) => Err(JoshutoError::IO(e)),
- }
+ LocalState::repopulated_selected_files(&curr_tab.curr_list)?;
+ LocalState::set_file_op(FileOp::Copy);
+ LocalState::set_tab_src(context.curr_tab_index);
+ Ok(())
}
}
@@ -159,21 +151,16 @@ impl std::fmt::Debug for PasteFiles {
}
impl JoshutoRunnable for PasteFiles {
- fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> {
let file_operation = FILE_OPERATION.lock().unwrap();
let thread = match *file_operation {
FileOp::Copy => self.copy_paste(context),
FileOp::Cut => self.cut_paste(context),
- };
+ }?;
- match thread {
- Ok(s) => {
- context.threads.push(s);
- Ok(())
- }
- Err(e) => Err(JoshutoError::IO(e)),
- }
+ context.threads.push(thread);
+ Ok(())
}
}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index b249072..1656af9 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -42,7 +42,7 @@ use std::path::PathBuf;
use crate::config::JoshutoCommandMapping;
use crate::context::JoshutoContext;
-use crate::error::{JoshutoError, KeymapError};
+use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::window::JoshutoView;
use crate::HOME_DIR;
@@ -54,8 +54,7 @@ pub enum CommandKeybind {
}
pub trait JoshutoRunnable {
- fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView)
- -> Result<(), JoshutoError>;
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()>;
}
pub trait JoshutoCommand: JoshutoRunnable + std::fmt::Display + std::fmt::Debug {}
@@ -69,23 +68,23 @@ impl std::fmt::Display for CommandKeybind {
}
}
-pub fn from_args(command: &str, args: &[&str]) -> Result<Box<JoshutoCommand>, KeymapError> {
+pub fn from_args(command: &str, args: &[&str]) -> JoshutoResult<Box<JoshutoCommand>> {
match command {
"cd" => match args.len() {
0 => match HOME_DIR.as_ref() {
Some(s) => Ok(Box::new(self::ChangeDirectory::new(s.clone()))),
- None => Err(KeymapError::new(
- Some("cd"),
- String::from("Cannot find home directory"),
+ None => Err(JoshutoError::new(
+ JoshutoErrorKind::EnvVarNotFound,
+ format!("{}: Cannot find home directory", command),
)),
},
1 => match args[0] {
".." => Ok(Box::new(self::ParentDirectory::new())),
arg => Ok(Box::new(self::ChangeDirectory::new(PathBuf::from(arg)))),
},
- i => Err(KeymapError::new(
- Some("cd"),
- format!("Expected 1 argument, got {}", i),
+ i => Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: Expected 1 argument, got {}", command, i),
)),
},
"close_tab" => Ok(Box::new(self::CloseTab::new())),
@@ -99,31 +98,37 @@ pub fn from_args(command: &str, args: &[&str]) -> Result<Box<JoshutoCommand>, Ke
String::from(args[0]),
String::new(),
))),
- i => Err(KeymapError::new(
- Some("console"),
- format!("Expected 0 or 2 arguments, got {}", i),
+ i => Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: Expected 0 or 2 arguments, got {}", command, i),
)),
},
"cursor_move_down" => match args.len() {
0 => Ok(Box::new(self::CursorMoveDown::new(1))),
1 => match args[0].parse::<usize>() {
Ok(s) => Ok(Box::new(self::CursorMoveDown::new(s))),
- Err(e) => Err(KeymapError::new(Some("cursor_move_down"), e.to_string())),
+ Err(e) => Err(JoshutoError::new(
+ JoshutoErrorKind::ParseError,
+ e.to_string(),
+ )),
},
- i => Err(KeymapError::new(
- Some("cursor_move_down"),
- format!("Expected 0 or 1 arguments, got {}", i),
+ i => Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: Expected 0 or 1 arguments, got {}", command, i),
)),
},
"cursor_move_up" => match args.len() {
0 => Ok(Box::new(self::CursorMoveUp::new(1))),
1 => match args[0].parse::<usize>() {
Ok(s) => Ok(Box::new(self::CursorMoveUp::new(s))),
- Err(e) => Err(KeymapError::new(Some("cursor_move_down"), e.to_string())),
+ Err(e) => Err(JoshutoError::new(
+ JoshutoErrorKind::ParseError,
+ format!("{}: {}", command, e.to_string()),
+ )),
},
- i => Err(KeymapError::new(
- Some("cursor_move_down"),
- format!("Expected 0 or 1 arguments, got {}", i),
+ i => Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: Expected 0 or 1 arguments, got {}", command, i),
)),
},
"cursor_move_home" => Ok(Box::new(self::CursorMoveHome::new())),
@@ -135,9 +140,9 @@ pub fn from_args(command: &str, args: &[&str]) -> Result<Box<JoshutoCommand>, Ke
"force_quit" => Ok(Box::new(self::ForceQuit::new())),
"mkdir" => {
if args.is_empty() {
- Err(KeymapError::new(
- Some("mkdir"),
- String::from("mkdir requires additional parameter"),
+ Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: missing additional parameter", command),
))
} else {
let paths: Vec<PathBuf> = args.iter().map(PathBuf::from).collect();
@@ -155,9 +160,9 @@ pub fn from_args(command: &str, args: &[&str]) -> Result<Box<JoshutoCommand>, Ke
"--overwrite" => options.overwrite = true,
"--skip_exist" => options.skip_exist = true,
_ => {
- return Err(KeymapError::new(
- Some("paste_files"),
- format!("unknown option {}", arg),
+ return Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: unknown option {}", command, arg),
));
}
}
@@ -171,18 +176,18 @@ pub fn from_args(command: &str, args: &[&str]) -> Result<Box<JoshutoCommand>, Ke
let path: PathBuf = PathBuf::from(args[0]);
Ok(Box::new(self::RenameFile::new(path)))
}
- i => Err(KeymapError::new(
- Some("rename_file"),
- format!("Expected 1, got {}", i),
+ i => Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("rename_file: Expected 1, got {}", i),
)),
},
"rename_append" => Ok(Box::new(self::RenameFileAppend::new())),
"rename_prepend" => Ok(Box::new(self::RenameFilePrepend::new())),
"search" => match args.len() {
1 => Ok(Box::new(self::Search::new(args[0]))),
- i => Err(KeymapError::new(
- Some("search"),
- format!("Expected 1, got {}", i),
+ i => Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: Expected 1, got {}", command, i),
)),
},
"search_next" => Ok(Box::new(self::SearchNext::new())),
@@ -195,9 +200,9 @@ pub fn from_args(command: &str, args: &[&str]) -> Result<Box<JoshutoCommand>, Ke
"--toggle" => toggle = true,
"--all" => all = true,
_ => {
- return Err(KeymapError::new(
- Some("select_files"),
- format!("unknown option {}", arg),
+ return Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: unknown option {}", command, arg),
));
}
}
@@ -209,17 +214,23 @@ pub fn from_args(command: &str, args: &[&str]) -> Result<Box<JoshutoCommand>, Ke
if args.len() == 1 {
match args[0].parse::<i32>() {
Ok(s) => Ok(Box::new(self::TabSwitch::new(s))),
- Err(e) => Err(KeymapError::new(Some("tab_switch"), e.to_string())),
+ Err(e) => Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: {}", command, e.to_string()),
+ )),
}
} else {
- Err(KeymapError::new(
- Some("tab_switch"),
- String::from("No option provided"),
+ Err(JoshutoError::new(
+ JoshutoErrorKind::IOInvalidData,
+ format!("{}: {}", command, "No option provided"),
))
}
}
"toggle_hidden" => Ok(Box::new(self::ToggleHiddenFiles::new())),
- inp => Err(KeymapError::new(None, format!("Unknown command: {}", inp))),
+ inp => Err(JoshutoError::new(
+ JoshutoErrorKind::UnknownCommand,
+ format!("{}: {}", "Unknown command", inp),
+ )),
}
}
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs
index 299d2a3..3684b0a 100644
--- a/src/commands/new_directory.rs
+++ b/src/commands/new_directory.rs
@@ -2,7 +2,7 @@ use std::path;
use crate::commands::{JoshutoCommand, JoshutoRunnable, ReloadDirList};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::window::JoshutoView;
#[derive(Clone, Debug)]
@@ -28,26 +28,14 @@ impl std::fmt::Display for NewDirectory {
}
impl JoshutoRunnable for NewDirectory {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
for path in &self.paths {
- match std::fs::create_dir_all(path) {
- Ok(_) => {}
- Err(e) => return Err(JoshutoError::IO(e)),
- }
- }
- let res = ReloadDirList::reload(context.curr_tab_index, context);
- match res {
- Ok(_) => {
- let curr_tab = &mut context.tabs[context.curr_tab_index];
- curr_tab.refresh(view, &context.config_t);
- ncurses::doupdate();
- }
- Err(e) => return Err(JoshutoError::IO(e)),
+ std::fs::create_dir_all(path)?;
}
+ ReloadDirList::reload(context.curr_tab_index, context)?;
+ let curr_tab = &mut context.tabs[context.curr_tab_index];
+ curr_tab.refresh(view, &context.config_t);
+ ncurses::doupdate();
Ok(())
}
}
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index f622b0b..42142a9 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::config::mimetype;
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::{JoshutoError, JoshutoResult};
use crate::history::DirectoryHistory;
use crate::textfield::JoshutoTextField;
use crate::ui;
@@ -119,14 +119,10 @@ impl std::fmt::Display for OpenFile {
}
impl JoshutoRunnable for OpenFile {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
match Self::open(context, view) {
Ok(_) => Ok(()),
- Err(e) => Err(JoshutoError::IO(e)),
+ Err(e) => Err(JoshutoError::from(e)),
}
}
}
@@ -211,7 +207,7 @@ impl std::fmt::Display for OpenFileWith {
}
impl JoshutoRunnable for OpenFileWith {
- fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> {
let curr_list = &context.tabs[context.curr_tab_index].curr_list;
let paths = curr_list.get_selected_paths();
Self::open_with(&paths);
diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs
index abafc21..f0f690d 100644
--- a/src/commands/parent_directory.rs
+++ b/src/commands/parent_directory.rs
@@ -1,6 +1,6 @@
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::{JoshutoError, JoshutoResult};
use crate::history::DirectoryHistory;
use crate::window::JoshutoView;
@@ -18,7 +18,7 @@ impl ParentDirectory {
pub fn parent_directory(
context: &mut JoshutoContext,
view: &JoshutoView,
- ) -> Result<(), std::io::Error> {
+ ) -> std::io::Result<()> {
let curr_tab = &mut context.tabs[context.curr_tab_index];
if !curr_tab.curr_path.pop() {
return Ok(());
@@ -49,14 +49,10 @@ impl std::fmt::Display for ParentDirectory {
}
impl JoshutoRunnable for ParentDirectory {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
match Self::parent_directory(context, view) {
Ok(_) => Ok(()),
- Err(e) => Err(JoshutoError::IO(e)),
+ Err(e) => Err(JoshutoError::from(e)),
}
}
}
diff --git a/src/commands/quit.rs b/src/commands/quit.rs
index aa19d5b..cdeca68 100644
--- a/src/commands/quit.rs
+++ b/src/commands/quit.rs
@@ -1,6 +1,6 @@
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::window::JoshutoView;
#[derive(Clone, Debug)]
@@ -14,13 +14,12 @@ impl Quit {
"quit"
}
- pub fn quit(context: &mut JoshutoContext) -> Result<(), JoshutoError> {
+ pub fn quit(context: &mut JoshutoContext) -> JoshutoResult<()> {
if !context.threads.is_empty() {
- let err = std::io::Error::new(
- std::io::ErrorKind::Other,
- "operations running in background, use force_quit to quit",
- );
- Err(JoshutoError::IO(err))
+ Err(JoshutoError::new(
+ JoshutoErrorKind::IOOther,
+ String::from("operations running in background, use force_quit to quit"),
+ ))
} else {
context.exit = true;
Ok(())
@@ -37,7 +36,7 @@ impl std::fmt::Display for Quit {
}
impl JoshutoRunnable for Quit {
- fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> {
Self::quit(context)
}
}
@@ -73,7 +72,7 @@ impl std::fmt::Display for ForceQuit {
}
impl JoshutoRunnable for ForceQuit {
- fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, _: &JoshutoView) -> JoshutoResult<()> {
Self::force_quit(context);
Ok(())
}
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs
index b69b2c5..f126f02 100644
--- a/src/commands/reload_dir.rs
+++ b/src/commands/reload_dir.rs
@@ -1,6 +1,6 @@
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::fs::JoshutoDirList;
use crate::window::JoshutoView;
@@ -47,19 +47,11 @@ impl std::fmt::Display for ReloadDirList {
}
impl JoshutoRunnable for ReloadDirList {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
- match Self::reload(context.curr_tab_index, context) {
- Ok(_) => {
- let curr_tab = &mut context.tabs[context.curr_tab_index];
- curr_tab.refresh(view, &context.config_t);
- ncurses::doupdate();
- Ok(())
- }
- Err(e) => Err(JoshutoError::IO(e)),
- }
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
+ Self::reload(context.curr_tab_index, context)?;
+ let curr_tab = &mut context.tabs[context.curr_tab_index];
+ curr_tab.refresh(view, &context.config_t);
+ ncurses::doupdate();
+ Ok(())
}
}
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index a43de07..02eadfb 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -2,7 +2,7 @@ use std::path;
use crate::commands::{CommandLine, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::window::JoshutoView;
use rustyline::completion::{escape, Quote};
@@ -60,11 +60,7 @@ impl std::fmt::Display for RenameFile {
}
impl JoshutoRunnable for RenameFile {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let mut path: Option<path::PathBuf> = None;
let curr_list = &context.tabs[context.curr_tab_index].curr_list;
@@ -73,10 +69,7 @@ impl JoshutoRunnable for RenameFile {
}
if let Some(path) = path {
- match self.rename_file(&path, context, view) {
- Ok(_) => {}
- Err(e) => return Err(JoshutoError::IO(e)),
- }
+ self.rename_file(&path, context, view)?;
ncurses::doupdate();
}
Ok(())
@@ -99,7 +92,7 @@ impl RenameFileAppend {
context: &mut JoshutoContext,
view: &JoshutoView,
file_name: String,
- ) -> Result<(), JoshutoError> {
+ ) -> JoshutoResult<()> {
let prefix;
let suffix;
if let Some(ext) = file_name.rfind('.') {
@@ -124,11 +117,7 @@ impl std::fmt::Display for RenameFileAppend {
}
impl JoshutoRunnable for RenameFileAppend {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let curr_list = &context.tabs[context.curr_tab_index].curr_list;
let file_name = match curr_list.get_curr_ref() {
Some(s) => {
@@ -167,7 +156,7 @@ impl RenameFilePrepend {
context: &mut JoshutoContext,
view: &JoshutoView,
file_name: String,
- ) -> Result<(), JoshutoError> {
+ ) -> JoshutoResult<()> {
let prefix = String::from("rename ");
let suffix = file_name;
@@ -185,11 +174,7 @@ impl std::fmt::Display for RenameFilePrepend {
}
impl JoshutoRunnable for RenameFilePrepend {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let curr_list = &context.tabs[context.curr_tab_index].curr_list;
let file_name = match curr_list.get_curr_ref() {
Some(s) => {
diff --git a/src/commands/search.rs b/src/commands/search.rs