summaryrefslogtreecommitdiffstats
path: root/src/commands/parent_directory.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-14 17:57:50 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-14 17:57:50 -0400
commit71e0c7faf3cc283b2b24e70631e5b18a7a7525cd (patch)
treeb27794c91a930ae2a1bc5cdc6a468b9b4d553134 /src/commands/parent_directory.rs
parent5a820a7a275bf5cacd2c545c0a0ac533789ec349 (diff)
rework error handling system
rather than letting each command separately handle errors, we return a Result<(), JoshutoError> instead and allow for run.rs to handle all errors
Diffstat (limited to 'src/commands/parent_directory.rs')
-rw-r--r--src/commands/parent_directory.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs
index fe219df..59a6122 100644
--- a/src/commands/parent_directory.rs
+++ b/src/commands/parent_directory.rs
@@ -1,5 +1,6 @@
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
+use crate::error::JoshutoError;
use crate::preview;
use crate::ui;
use crate::window::JoshutoView;
@@ -15,9 +16,12 @@ impl ParentDirectory {
"parent_directory"
}
- pub fn parent_directory(context: &mut JoshutoContext, view: &JoshutoView) {
+ pub fn parent_directory(
+ context: &mut JoshutoContext,
+ view: &JoshutoView,
+ ) -> Result<(), JoshutoError> {
if !context.curr_tab_mut().curr_path.pop() {
- return;
+ return Ok(());
}
match std::env::set_current_dir(&context.curr_tab_ref().curr_path) {
@@ -54,12 +58,13 @@ impl ParentDirectory {
&context.hostname,
);
preview::preview_file(curr_tab, view, &context.config_t);
+ ncurses::doupdate();
+ return Ok(());
}
Err(e) => {
- ui::wprint_err(&view.bot_win, e.to_string().as_str());
+ return Err(JoshutoError::IO(e));
}
};
- ncurses::doupdate();
}
}
@@ -72,7 +77,11 @@ impl std::fmt::Display for ParentDirectory {
}
impl JoshutoRunnable for ParentDirectory {
- fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) {
- Self::parent_directory(context, view);
+ fn execute(
+ &self,
+ context: &mut JoshutoContext,
+ view: &JoshutoView,
+ ) -> Result<(), JoshutoError> {
+ Self::parent_directory(context, view)
}
}