From 9466db743f65403e1f220ac9f5fe184ccd4ac0b0 Mon Sep 17 00:00:00 2001 From: n Date: Mon, 1 Sep 2025 04:51:16 +0200 Subject: [PATCH 1/2] add some vim keybinds for navigation --- src/main.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9afc08a..8bf7d3f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -502,25 +502,37 @@ fn print_paged(graph_lines: &[String], text_lines: &[String]) -> Result<(), Erro let input = crossterm::event::read()?; if let Event::Key(evt) = input { match evt.code { - KeyCode::Down => { + KeyCode::Down | KeyCode::Char('j') => { start_idx += 1; should_update = true; } - KeyCode::Up => { + KeyCode::Up | KeyCode::Char('k') => { if start_idx > 0 { start_idx -= 1; should_update = true; } } - KeyCode::Enter | KeyCode::PageDown => { + KeyCode::Enter | KeyCode::PageDown | KeyCode::Char('f') => { start_idx += height as usize - 2; should_update = true; } - KeyCode::End => { + KeyCode::End | KeyCode::Char('G') => { start_idx = graph_lines.len() - height as usize - 2; should_update = true; // TODO: maybe make this better } + KeyCode::PageUp | KeyCode::Char('b') => { + if start_idx >= height as usize - 2 { + start_idx -= height as usize - 2; + } else { + start_idx = 0; + } + should_update = true; + } + KeyCode::Home | KeyCode::Char('g') => { + start_idx = 0; + should_update = true; + } KeyCode::Char(c) => match c { 'q' => { break; From cea9ea053cbeabd133b6b6f45d95f404e9f80db4 Mon Sep 17 00:00:00 2001 From: n Date: Wed, 3 Sep 2025 15:25:03 +0200 Subject: [PATCH 2/2] fix linter errors --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8bf7d3f..b6f4266 100644 --- a/src/main.rs +++ b/src/main.rs @@ -516,7 +516,7 @@ fn print_paged(graph_lines: &[String], text_lines: &[String]) -> Result<(), Erro start_idx += height as usize - 2; should_update = true; } - KeyCode::End | KeyCode::Char('G') => { + KeyCode::End | KeyCode::Char('G') => { start_idx = graph_lines.len() - height as usize - 2; should_update = true; // TODO: maybe make this better @@ -529,7 +529,7 @@ fn print_paged(graph_lines: &[String], text_lines: &[String]) -> Result<(), Erro } should_update = true; } - KeyCode::Home | KeyCode::Char('g') => { + KeyCode::Home | KeyCode::Char('g') => { start_idx = 0; should_update = true; }