diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-29 22:19:47 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-29 22:23:31 -0400 |
commit | 65f0f33a564d91bd8126ce684c02f245e5ea9a1f (patch) | |
tree | bc9bb5d877cee131dc7870c5f9f5d0c71898efbd /src/commands/cursor_move.rs | |
parent | 58f6428e2aead58b7f930008b294ce56df59e3cb (diff) |
rework error system
- JoshutoErrorKind now envelops all possible errors by Joshuto
- JoshutoError behaves like std::io::Error
- add JoshutoResult
Diffstat (limited to 'src/commands/cursor_move.rs')
-rw-r--r-- | src/commands/cursor_move.rs | 38 |
1 files changed, 7 insertions, 31 deletions
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 { |