Skip to content

Commit

Permalink
Improve navigation in analyzer mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rincewound committed Dec 10, 2024
1 parent 4670b72 commit 7351ffb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ Normal --> Analyzer

### Interactive

* Up - Scroll Receive Buffer Up
* Down - Scroll Receive Buffer Down
* PageUp - Scroll Receive Buffer Up
* PageDown - Scroll Receive Buffer Down
* Enter - Send current send buffer (according to CRLF and Input settings)
* F3 - Change input mode
* F4 - Change CRLF mode
Expand All @@ -65,8 +65,8 @@ Normal --> Analyzer

_Note_: Analyzer Features are only available in display HEX mode.

* Up/Down - Scroll Receive buffer
* Left/Right - Move analyzer cursor
* PageUp/PageDown - Scroll Receive buffer
* Up/Down/Left/Right - Move analyzer cursor
* e - switch endianness

## Display modes
Expand Down
19 changes: 16 additions & 3 deletions src/analyzer_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct AnalyzerMode {
active: bool,
display_history: Vec<SerialStateMessage>,
scroll_offset: u32,
analyzer_cursor_line: usize,
analyzer_cursor_pos: usize,
analyzer_endianness: Endianness,
active_display_mode: DisplayMode,
Expand All @@ -47,6 +48,7 @@ impl AnalyzerMode {
active: false,
display_history: vec![],
scroll_offset: 0,
analyzer_cursor_line: 0,
analyzer_cursor_pos: 0,
analyzer_endianness: Endianness::Little,
active_display_mode: DisplayMode::Hex,
Expand All @@ -59,8 +61,11 @@ impl ApplicationMode for AnalyzerMode {
match key_event.code {
KeyCode::Left => self.cursor_left(),
KeyCode::Right => self.cursor_right(),
KeyCode::Up => self.scroll_up(),
KeyCode::Down => self.scroll_down(),
KeyCode::Up => self.scroll_analyzer_cursor_up(),
KeyCode::Down => self.scroll_analyzer_cursor_down(),
KeyCode::PageUp => self.scroll_up(),
KeyCode::PageDown => self.scroll_down(),

//KeyCode::F(2) => self.settingsmode.rotate_display_mode(),
KeyCode::Char('e') => self.rotate_analyzer_endianness(),
_ => {}
Expand Down Expand Up @@ -100,6 +105,14 @@ impl AnalyzerMode {
self.scroll_offset = self.scroll_offset.saturating_add(1);
}

pub fn scroll_analyzer_cursor_up(&mut self) {
self.analyzer_cursor_line += 1;
}

pub fn scroll_analyzer_cursor_down(&mut self) {
self.analyzer_cursor_line = self.analyzer_cursor_line.saturating_sub(1);
}

/// Scroll down in the display history, moving the top line up by one.
pub fn scroll_down(&mut self) {
self.scroll_offset = self.scroll_offset.saturating_sub(1);
Expand Down Expand Up @@ -224,7 +237,7 @@ impl AnalyzerMode {
let mut post_cursor_color = ratatui::style::Color::Black;

if self.active_display_mode == DisplayMode::Hex
&& line_index == 0
&& line_index == self.analyzer_cursor_line
&& self.active
{
// the cursor pos is always a multiple of 3:
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ impl App {
fn do_interactive_mode(&mut self, key_event: KeyEvent) {
self.interactivemode.handle_key_event(key_event);
match key_event.code {
KeyCode::Up => self.analyzermode.scroll_up(),
KeyCode::Down => self.analyzermode.scroll_down(),
KeyCode::PageUp => self.analyzermode.scroll_up(),
KeyCode::PageDown => self.analyzermode.scroll_down(),
_ => {}
}
}
Expand Down

0 comments on commit 7351ffb

Please sign in to comment.