diff options
author | sushi-shi <47691267+sushi-shi@users.noreply.github.com> | 2022-02-24 20:30:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-24 12:30:39 -0500 |
commit | 55b401cfa35ee3ce09d2deba94f0d490ad666e9b (patch) | |
tree | 21b58d27c748389f275fda2e5f4a4dc2f5fa853d /src/commands | |
parent | 0f63648c13034ee76d661d8dc5efebf8f30c30cc (diff) |
Move half page (#143)
* Add console shortcuts
* Add support for proportional page movements
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/cursor_move.rs | 26 | ||||
-rw-r--r-- | src/commands/help.rs | 4 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index 5d9430f..60d4fd5 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -54,7 +54,7 @@ pub fn cursor_move(context: &mut AppContext, new_index: usize) { } } -pub fn up(context: &mut AppContext, u: usize) -> JoshutoResult<()> { +pub fn up(context: &mut AppContext, u: usize) -> JoshutoResult { let movement = match context.tab_context_ref().curr_tab_ref().curr_list_ref() { Some(curr_list) => curr_list .get_index() @@ -68,7 +68,7 @@ pub fn up(context: &mut AppContext, u: usize) -> JoshutoResult<()> { Ok(()) } -pub fn down(context: &mut AppContext, u: usize) -> JoshutoResult<()> { +pub fn down(context: &mut AppContext, u: usize) -> JoshutoResult { let movement = match context.tab_context_ref().curr_tab_ref().curr_list_ref() { Some(curr_list) => curr_list.get_index().map(|idx| idx + u), None => None, @@ -79,7 +79,7 @@ pub fn down(context: &mut AppContext, u: usize) -> JoshutoResult<()> { Ok(()) } -pub fn home(context: &mut AppContext) -> JoshutoResult<()> { +pub fn home(context: &mut AppContext) -> JoshutoResult { let movement: Option<usize> = match context.tab_context_ref().curr_tab_ref().curr_list_ref() { Some(curr_list) => { let len = curr_list.len(); @@ -98,7 +98,7 @@ pub fn home(context: &mut AppContext) -> JoshutoResult<()> { Ok(()) } -pub fn end(context: &mut AppContext) -> JoshutoResult<()> { +pub fn end(context: &mut AppContext) -> JoshutoResult { let movement: Option<usize> = match context.tab_context_ref().curr_tab_ref().curr_list_ref() { Some(curr_list) => { let len = curr_list.len(); @@ -135,8 +135,13 @@ fn get_page_size(context: &AppContext, backend: &TuiBackend) -> Option<usize> { } } -pub fn page_up(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult<()> { - let page_size = get_page_size(context, backend).unwrap_or(10); +pub fn page_up( + context: &mut AppContext, + backend: &mut TuiBackend, + proportion: f64, +) -> JoshutoResult { + let page_size = get_page_size(context, backend).unwrap_or(10) as f64 * proportion; + let page_size = page_size as usize; let movement = match context.tab_context_ref().curr_tab_ref().curr_list_ref() { Some(curr_list) => { @@ -153,8 +158,13 @@ pub fn page_up(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoRes Ok(()) } -pub fn page_down(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult<()> { - let page_size = get_page_size(context, backend).unwrap_or(10); +pub fn page_down( + context: &mut AppContext, + backend: &mut TuiBackend, + proportion: f64, +) -> JoshutoResult { + let page_size = get_page_size(context, backend).unwrap_or(10) as f64 * proportion; + let page_size = page_size as usize; let movement = match context.tab_context_ref().curr_tab_ref().curr_list_ref() { Some(curr_list) => { diff --git a/src/commands/help.rs b/src/commands/help.rs index d47a0f4..3c073bb 100644 --- a/src/commands/help.rs +++ b/src/commands/help.rs @@ -54,8 +54,8 @@ pub fn help_loop( Command::CursorMoveDown(_) => move_offset(&mut offset, 1), Command::CursorMoveHome => offset = 0, Command::CursorMoveEnd => offset = 255, - Command::CursorMovePageUp => move_offset(&mut offset, -10), - Command::CursorMovePageDown => move_offset(&mut offset, 10), + Command::CursorMovePageUp(_) => move_offset(&mut offset, -10), + Command::CursorMovePageDown(_) => move_offset(&mut offset, 10), Command::CloseTab | Command::Help => break, _ => (), } |