diff --git a/boot_diags/src/components/logview.rs b/boot_diags/src/components/logview.rs index 58b11a0..7707925 100644 --- a/boot_diags/src/components/logview.rs +++ b/boot_diags/src/components/logview.rs @@ -27,7 +27,10 @@ use core::{ config::Config, state::Mode, }; -use std::sync::{Arc, Mutex}; +use std::{ + cmp::min, + sync::{Arc, Mutex}, +}; use crate::diags::DiagGroup; @@ -75,11 +78,51 @@ impl Component for LogView { } Action::KeyDown => { if self.mode == Mode::LogView { - self.line_index = self.line_index + 1; + let new_index = self.line_index + 1; + if let Some(log_text) = self.list.get_selected() { + let lines: Vec<&str> = log_text.split('\n').collect(); + if new_index as usize > lines.len() { + self.line_index = lines.len() as u16; + } else { + self.line_index = new_index; + } + } } else { self.list.next(); } } + Action::KeyPageUp => { + if self.mode == Mode::LogView { + if self.line_index > 10 { + self.line_index -= 10; + } else { + self.line_index = 0; + } + } + } + Action::KeyPageDown => { + if self.mode == Mode::LogView { + let new_index = self.line_index + 10; + if let Some(log_text) = self.list.get_selected() { + let lines: Vec<&str> = log_text.split('\n').collect(); + let new_index: u16 = min((lines.len() - 3) as u16, new_index); + self.line_index = new_index; + } + } + } + Action::KeyHome => { + if self.mode == Mode::LogView { + self.line_index = 0; + } + } + Action::KeyEnd => { + if self.mode == Mode::LogView { + if let Some(log_text) = self.list.get_selected() { + let lines: Vec<&str> = log_text.split('\n').collect(); + self.line_index = (lines.len() - 3) as u16; + } + } + } Action::Process => { if self.mode == Mode::LogView { if let Some(command_tx) = self.command_tx.clone() { diff --git a/config/config.json5 b/config/config.json5 index 6fbdb61..3dec46f 100644 --- a/config/config.json5 +++ b/config/config.json5 @@ -137,6 +137,10 @@ "": "Process", "": "KeyUp", "": "KeyDown", + "": "KeyPageUp", + "": "KeyPageDown", + "": "KeyHome", + "": "KeyEnd", "": "Quit", "": "Quit", "": "Quit", diff --git a/core/src/action.rs b/core/src/action.rs index b956748..34bf83a 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -69,6 +69,10 @@ pub enum Action { KeyUp, KeyLeft, KeyRight, + KeyPageUp, + KeyPageDown, + KeyHome, + KeyEnd, Quit, Render, Resize(u16, u16),