better span view
This commit is contained in:
parent
43e40b61e3
commit
fdfc08e88b
12 changed files with 612 additions and 206 deletions
|
|
@ -7,12 +7,11 @@ use crate::tui::{
|
|||
input::{FieldMatcher, InputState, InputTarget},
|
||||
view::LogView,
|
||||
},
|
||||
model::{LogEntry, id},
|
||||
model::{FieldsName, LogEntry, id},
|
||||
processing::Cursor,
|
||||
widgets::last_error::LastError,
|
||||
widgets::{fieldtree, last_error::LastError},
|
||||
};
|
||||
use dumpster::sync::Gc;
|
||||
use tui_widget_list::ListState;
|
||||
|
||||
pub mod filters;
|
||||
pub mod input;
|
||||
|
|
@ -28,9 +27,10 @@ pub struct LogViewer {
|
|||
pub last_fields_offset: usize,
|
||||
pub last_fields_height: usize,
|
||||
|
||||
pub footer_list: ListState,
|
||||
pub filters: Filters,
|
||||
pub input_state: InputState,
|
||||
|
||||
pub field_state: fieldtree::State,
|
||||
}
|
||||
|
||||
impl LogViewer {
|
||||
|
|
@ -42,7 +42,6 @@ impl LogViewer {
|
|||
selection_offset: 0,
|
||||
},
|
||||
cache: HashMap::new(),
|
||||
footer_list: ListState::default(),
|
||||
|
||||
last_height: 0,
|
||||
last_offset: 0,
|
||||
|
|
@ -51,9 +50,20 @@ impl LogViewer {
|
|||
|
||||
filters,
|
||||
input_state: InputState::None,
|
||||
field_state: fieldtree::State::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_selected_field(&self) -> Option<(FieldsName, String, String)> {
|
||||
let (span_idx, name_idx) = self.field_state.get()?;
|
||||
let entry = self.selected().map(|(s, _)| s)?;
|
||||
|
||||
let (span, fields) = entry.spans().named().nth(span_idx)?;
|
||||
let (name, value) = fields.fields.iter().nth(name_idx)?;
|
||||
|
||||
Some((span, name.clone(), value.clone()))
|
||||
}
|
||||
|
||||
pub fn add_filter(&mut self, filter: Arc<Filter>) {
|
||||
self.filters.push(Arc::clone(&filter));
|
||||
if !self.view.cursor.update_with_parents(&self.filters) {
|
||||
|
|
@ -72,27 +82,27 @@ impl LogViewer {
|
|||
self.last_height = num_visible_items;
|
||||
}
|
||||
|
||||
pub fn footer_fields(&self) -> Vec<(String, String)> {
|
||||
if let Some((selected, _)) = self.selected() {
|
||||
let ret = match selected.as_ref() {
|
||||
LogEntry::Single { .. } => Default::default(),
|
||||
LogEntry::Sub { children, .. } => children.last_child.as_ref().and_then(|i| {
|
||||
i.all_fields()
|
||||
.get_key_value("return")
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
}),
|
||||
};
|
||||
|
||||
selected
|
||||
.all_relevant_fields()
|
||||
.fields
|
||||
.into_iter()
|
||||
.chain(ret)
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
// pub fn footer_fields(&self) -> Vec<(String, String)> {
|
||||
// if let Some((selected, _)) = self.selected() {
|
||||
// let ret = match selected.as_ref() {
|
||||
// LogEntry::Single { .. } => Default::default(),
|
||||
// LogEntry::Sub { children, .. } => children.last_child.as_ref().and_then(|i| {
|
||||
// i.all_fields()
|
||||
// .get_key_value("return")
|
||||
// .map(|(k, v)| (k.clone(), v.clone()))
|
||||
// }),
|
||||
// };
|
||||
//
|
||||
// selected
|
||||
// .all_relevant_fields()
|
||||
// .fields
|
||||
// .into_iter()
|
||||
// .chain(ret)
|
||||
// .collect::<Vec<_>>()
|
||||
// } else {
|
||||
// Vec::new()
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn items(&mut self, max: usize) -> Option<(Vec<(Gc<LogEntry>, usize)>, usize)> {
|
||||
let mut temp_iter = self.view.cursor.clone();
|
||||
|
|
@ -131,7 +141,8 @@ impl LogViewer {
|
|||
if row_in_fields < self.last_fields_height {
|
||||
self.input_state =
|
||||
InputState::Target(InputTarget::Fields(Some(FieldMatcher::EqualTo)));
|
||||
self.footer_list.select(Some(row_in_fields));
|
||||
todo!()
|
||||
// self.footer_list.select(Some(row_in_fields));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,7 +154,7 @@ impl LogViewer {
|
|||
pub fn prev(&mut self) {
|
||||
match self.input_state {
|
||||
InputState::Target(InputTarget::Fields(..)) => {
|
||||
self.footer_list.previous();
|
||||
self.field_state.up();
|
||||
self.input_state = InputState::Target(InputTarget::Fields(None));
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -160,7 +171,7 @@ impl LogViewer {
|
|||
pub fn next(&mut self) {
|
||||
match self.input_state {
|
||||
InputState::Target(InputTarget::Fields(..)) => {
|
||||
self.footer_list.next();
|
||||
self.field_state.down();
|
||||
self.input_state = InputState::Target(InputTarget::Fields(None));
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -189,7 +200,7 @@ impl LogViewer {
|
|||
pub fn home(&mut self) {
|
||||
match self.input_state {
|
||||
InputState::Target(InputTarget::Fields(..)) => {
|
||||
self.footer_list.select(Some(0));
|
||||
self.field_state.home();
|
||||
self.input_state = InputState::Target(InputTarget::Fields(None));
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -218,13 +229,21 @@ impl LogViewer {
|
|||
}
|
||||
|
||||
pub fn back(&mut self) {
|
||||
self.add_to_cache();
|
||||
if self.view.cursor.exit(&self.filters) {
|
||||
self.update_offset_from_cache();
|
||||
self.view.cursor.prev(&self.filters);
|
||||
match self.input_state {
|
||||
InputState::None => {
|
||||
self.add_to_cache();
|
||||
if self.view.cursor.exit(&self.filters) {
|
||||
self.update_offset_from_cache();
|
||||
self.view.cursor.prev(&self.filters);
|
||||
}
|
||||
// self.cache.insert(self.path(), self.curr.clone());
|
||||
self.input_state.reset();
|
||||
}
|
||||
InputState::Target(InputTarget::Fields(None)) => {
|
||||
self.field_state.left();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// self.cache.insert(self.path(), self.curr.clone());
|
||||
self.input_state.reset();
|
||||
}
|
||||
|
||||
pub fn undo(&mut self) {
|
||||
|
|
@ -235,6 +254,18 @@ impl LogViewer {
|
|||
self.filters.redo();
|
||||
}
|
||||
|
||||
pub fn right(&mut self) {
|
||||
match self.input_state {
|
||||
InputState::None => {
|
||||
self.enter();
|
||||
}
|
||||
InputState::Target(InputTarget::Fields(None)) => {
|
||||
self.field_state.right();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter(&mut self) {
|
||||
match self.input_state {
|
||||
InputState::None => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue