help overview and input rework
This commit is contained in:
parent
a6d501977c
commit
f733c65bcf
3 changed files with 275 additions and 214 deletions
|
|
@ -32,6 +32,25 @@ impl Clone for LogView {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum InputTarget {
|
||||
Fields,
|
||||
}
|
||||
|
||||
pub enum InputState {
|
||||
None,
|
||||
Target(InputTarget),
|
||||
}
|
||||
|
||||
impl InputState {
|
||||
pub fn reset(&mut self) {
|
||||
*self = Self::None;
|
||||
}
|
||||
|
||||
pub fn target(&mut self, target: InputTarget) {
|
||||
*self = Self::Target(target);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LogViewer {
|
||||
stack: Vec<LogView>,
|
||||
curr: LogView,
|
||||
|
|
@ -40,8 +59,9 @@ pub struct LogViewer {
|
|||
|
||||
pub root_stream: Box<dyn LogStream>,
|
||||
pub last_height: usize,
|
||||
pub footer_selected: bool,
|
||||
pub footer_list: ListState,
|
||||
|
||||
pub input_state: InputState,
|
||||
}
|
||||
|
||||
impl LogViewer {
|
||||
|
|
@ -55,9 +75,9 @@ impl LogViewer {
|
|||
root_stream: stream.clone(),
|
||||
cache: HashMap::new(),
|
||||
footer_list: ListState::default(),
|
||||
footer_selected: false,
|
||||
last_height: 0,
|
||||
filters: Vec::new(),
|
||||
input_state: InputState::None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -224,36 +244,35 @@ impl LogViewer {
|
|||
self.curr.selected()
|
||||
}
|
||||
|
||||
fn update_footer_select(&mut self) {
|
||||
self.footer_list.select(Some(0));
|
||||
}
|
||||
|
||||
pub fn prev(&mut self) {
|
||||
if self.footer_selected {
|
||||
self.footer_list.previous();
|
||||
} else {
|
||||
if self.curr.selection_offset == 0 {
|
||||
let _ = self.curr.iter.prev();
|
||||
} else {
|
||||
self.curr.selection_offset -= 1;
|
||||
match self.input_state {
|
||||
InputState::None => {
|
||||
if self.curr.selection_offset == 0 {
|
||||
let _ = self.curr.iter.prev();
|
||||
} else {
|
||||
self.curr.selection_offset -= 1;
|
||||
}
|
||||
}
|
||||
InputState::Target(InputTarget::Fields) => {
|
||||
self.footer_list.previous();
|
||||
}
|
||||
self.update_footer_select();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
if self.footer_selected {
|
||||
self.footer_list.next();
|
||||
} else {
|
||||
self.curr.selection_offset += 1;
|
||||
self.update_footer_select();
|
||||
match self.input_state {
|
||||
InputState::None => {
|
||||
self.curr.selection_offset += 1;
|
||||
}
|
||||
InputState::Target(InputTarget::Fields) => {
|
||||
self.footer_list.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn page_down(&mut self) {
|
||||
self.curr.selection_offset += self.last_height;
|
||||
self.footer_selected = false;
|
||||
self.update_footer_select();
|
||||
self.input_state.reset();
|
||||
}
|
||||
|
||||
pub fn page_up(&mut self) {
|
||||
|
|
@ -264,17 +283,18 @@ impl LogViewer {
|
|||
self.curr.selection_offset -= 1;
|
||||
}
|
||||
}
|
||||
self.footer_selected = false;
|
||||
self.update_footer_select();
|
||||
self.input_state.reset();
|
||||
}
|
||||
|
||||
pub fn home(&mut self) {
|
||||
if self.footer_selected {
|
||||
self.footer_list.select(Some(0));
|
||||
} else {
|
||||
self.curr.selection_offset = 0;
|
||||
while self.curr.iter.prev().is_some() {}
|
||||
self.update_footer_select();
|
||||
match self.input_state {
|
||||
InputState::None => {
|
||||
self.curr.selection_offset = 0;
|
||||
while self.curr.iter.prev().is_some() {}
|
||||
}
|
||||
InputState::Target(InputTarget::Fields) => {
|
||||
self.footer_list.select(Some(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -287,34 +307,33 @@ impl LogViewer {
|
|||
if let Some(stack) = self.stack.pop() {
|
||||
self.curr = stack;
|
||||
}
|
||||
self.footer_selected = false;
|
||||
self.update_footer_select();
|
||||
}
|
||||
|
||||
pub fn switch_focus(&mut self) {
|
||||
self.footer_selected = !self.footer_selected;
|
||||
self.input_state.reset();
|
||||
}
|
||||
|
||||
pub fn enter(&mut self) {
|
||||
if !self.footer_selected {
|
||||
let Some((s, _)) = self.selected() else {
|
||||
return;
|
||||
};
|
||||
let Some(i) = s.from_start(0) else {
|
||||
return;
|
||||
};
|
||||
match self.input_state {
|
||||
InputState::None => {
|
||||
let Some((s, _)) = self.selected() else {
|
||||
return;
|
||||
};
|
||||
let Some(i) = s.from_start(0) else {
|
||||
return;
|
||||
};
|
||||
|
||||
self.stack.push(mem::replace(
|
||||
&mut self.curr,
|
||||
LogView {
|
||||
iter: Box::new(i),
|
||||
selection_offset: 0,
|
||||
},
|
||||
));
|
||||
if let Some(cached_view) = self.cache.get(&self.path()) {
|
||||
self.curr = cached_view.clone();
|
||||
self.stack.push(mem::replace(
|
||||
&mut self.curr,
|
||||
LogView {
|
||||
iter: Box::new(i),
|
||||
selection_offset: 0,
|
||||
},
|
||||
));
|
||||
if let Some(cached_view) = self.cache.get(&self.path()) {
|
||||
self.curr = cached_view.clone();
|
||||
}
|
||||
}
|
||||
InputState::Target(InputTarget::Fields) => {
|
||||
self.footer_list.next();
|
||||
}
|
||||
self.update_footer_select();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue