diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-14 17:57:50 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-04-14 17:57:50 -0400 |
commit | 71e0c7faf3cc283b2b24e70631e5b18a7a7525cd (patch) | |
tree | b27794c91a930ae2a1bc5cdc6a468b9b4d553134 /src/commands/cursor_move.rs | |
parent | 5a820a7a275bf5cacd2c545c0a0ac533789ec349 (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/cursor_move.rs')
-rw-r--r-- | src/commands/cursor_move.rs | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index 57e629d..f9be9fb 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -1,5 +1,6 @@ use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; +use crate::error::JoshutoError; use crate::preview; use crate::window::JoshutoView; @@ -60,7 +61,11 @@ impl std::fmt::Display for CursorMoveInc { } impl JoshutoRunnable for CursorMoveInc { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { + fn execute( + &self, + context: &mut JoshutoContext, + view: &JoshutoView, + ) -> Result<(), JoshutoError> { let mut movement: Option<usize> = None; { let curr_tab = context.curr_tab_mut(); @@ -69,8 +74,9 @@ impl JoshutoRunnable for CursorMoveInc { } } if let Some(s) = movement { - CursorMove::cursor_move(s, context, view); + CursorMove::cursor_move(s, context, view) } + Ok(()) } } @@ -97,7 +103,11 @@ impl std::fmt::Display for CursorMoveDec { } impl JoshutoRunnable for CursorMoveDec { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { + fn execute( + &self, + context: &mut JoshutoContext, + view: &JoshutoView, + ) -> Result<(), JoshutoError> { let mut movement: Option<usize> = None; { let curr_tab = context.curr_tab_mut(); @@ -114,6 +124,7 @@ impl JoshutoRunnable for CursorMoveDec { if let Some(s) = movement { CursorMove::cursor_move(s, context, view); } + Ok(()) } } @@ -138,7 +149,11 @@ impl std::fmt::Display for CursorMovePageUp { } impl JoshutoRunnable for CursorMovePageUp { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { + fn execute( + &self, + context: &mut JoshutoContext, + view: &JoshutoView, + ) -> Result<(), JoshutoError> { let movement: Option<usize> = { let curr_tab = context.curr_tab_mut(); if let Some(curr_list) = curr_tab.curr_list.as_ref() { @@ -154,6 +169,7 @@ impl JoshutoRunnable for CursorMovePageUp { if let Some(s) = movement { CursorMove::cursor_move(s, context, view); } + Ok(()) } } @@ -178,7 +194,11 @@ impl std::fmt::Display for CursorMovePageDown { } impl JoshutoRunnable for CursorMovePageDown { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { + fn execute( + &self, + context: &mut JoshutoContext, + view: &JoshutoView, + ) -> Result<(), JoshutoError> { let movement: Option<usize> = { let curr_tab = &mut context.tabs[context.curr_tab_index]; if let Some(curr_list) = curr_tab.curr_list.as_ref() { @@ -199,6 +219,7 @@ impl JoshutoRunnable for CursorMovePageDown { if let Some(s) = movement { CursorMove::cursor_move(s, context, view); } + Ok(()) } } @@ -223,7 +244,11 @@ impl std::fmt::Display for CursorMoveHome { } impl JoshutoRunnable for CursorMoveHome { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { + fn execute( + &self, + context: &mut JoshutoContext, + view: &JoshutoView, + ) -> Result<(), JoshutoError> { let movement: Option<usize> = { let curr_tab = context.curr_tab_mut(); if let Some(curr_list) = curr_tab.curr_list.as_ref() { @@ -240,6 +265,7 @@ impl JoshutoRunnable for CursorMoveHome { if let Some(s) = movement { CursorMove::cursor_move(s, context, view); } + Ok(()) } } @@ -264,7 +290,11 @@ impl std::fmt::Display for CursorMoveEnd { } impl JoshutoRunnable for CursorMoveEnd { - fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) { + fn execute( + &self, + context: &mut JoshutoContext, + view: &JoshutoView, + ) -> Result<(), JoshutoError> { let movement: Option<usize> = { let curr_tab = context.curr_tab_mut(); if let Some(curr_list) = curr_tab.curr_list.as_ref() { @@ -278,5 +308,6 @@ impl JoshutoRunnable for CursorMoveEnd { if let Some(s) = movement { CursorMove::cursor_move(s, context, view); } + Ok(()) } } |