Expand LogView key handling
This commit is contained in:
parent
3fafcc4292
commit
3340114522
3 changed files with 53 additions and 2 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -137,6 +137,10 @@
|
|||
"<Esc>": "Process",
|
||||
"<Up>": "KeyUp",
|
||||
"<Down>": "KeyDown",
|
||||
"<PageUp>": "KeyPageUp",
|
||||
"<PageDown>": "KeyPageDown",
|
||||
"<Home>": "KeyHome",
|
||||
"<End>": "KeyEnd",
|
||||
"<q>": "Quit",
|
||||
"<Ctrl-d>": "Quit",
|
||||
"<Ctrl-c>": "Quit",
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ pub enum Action {
|
|||
KeyUp,
|
||||
KeyLeft,
|
||||
KeyRight,
|
||||
KeyPageUp,
|
||||
KeyPageDown,
|
||||
KeyHome,
|
||||
KeyEnd,
|
||||
Quit,
|
||||
Render,
|
||||
Resize(u16, u16),
|
||||
|
|
|
|||
Loading…
Reference in a new issue