mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-04 02:24:11 +02:00
store logline references instead of indirecting trough logindex
This commit is contained in:
parent
c5af0ac37a
commit
dc4b5d2853
7 changed files with 80 additions and 86 deletions
|
|
@ -1,6 +1,5 @@
|
|||
use crate::app::{App, Filter};
|
||||
use crate::logfile::logline::{format_time, LogLine};
|
||||
use crate::logs::LogIndex;
|
||||
use crate::ui::state::GroupedLogGrouping;
|
||||
use crate::ui::style::TABLE_HEADER_STYLE;
|
||||
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
|
||||
|
|
@ -12,7 +11,7 @@ use ratatui::text::Text;
|
|||
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
|
||||
|
||||
pub struct GroupedLogs<'a> {
|
||||
lines: &'a [LogIndex],
|
||||
lines: &'a [&'a LogLine<'a>],
|
||||
app: &'a App<'a>,
|
||||
filter: &'a Filter,
|
||||
grouping: GroupedLogGrouping,
|
||||
|
|
@ -20,7 +19,7 @@ pub struct GroupedLogs<'a> {
|
|||
|
||||
pub fn grouped_logs<'a>(
|
||||
app: &'a App<'a>,
|
||||
lines: &'a [LogIndex],
|
||||
lines: &'a [&'a LogLine<'a>],
|
||||
filter: &'a Filter,
|
||||
grouping: GroupedLogGrouping,
|
||||
) -> GroupedLogs<'a> {
|
||||
|
|
@ -39,12 +38,11 @@ impl StatefulWidget for GroupedLogs<'_> {
|
|||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let lines = self.lines.iter().copied().map(|i| self.app.get_line(i));
|
||||
let lines = self.lines.iter().copied();
|
||||
let line = self
|
||||
.lines
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|i| &self.app.lines[i])
|
||||
.filter(|line| line.matches(self.filter))
|
||||
.nth(state.selected())
|
||||
.unwrap_or(self.app.lines.first());
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub fn grouped_lines<'a>(
|
|||
|
||||
pub struct SingleMatchTable<'a> {
|
||||
app: &'a App<'a>,
|
||||
log_match: &'a LogMatch,
|
||||
log_match: &'a LogMatch<'a>,
|
||||
filter: &'a Filter,
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ impl StatefulWidget for SingleMatchTable<'_> {
|
|||
.chain(
|
||||
grouped
|
||||
.iter()
|
||||
.filter(|group| group.matches(self.app, self.filter))
|
||||
.filter(|group| group.matches(self.filter))
|
||||
.enumerate()
|
||||
.map(|(i, group)| {
|
||||
group_row(self.app, group, i.abs_diff(state.selected()) < 100)
|
||||
|
|
@ -80,7 +80,7 @@ impl StatefulWidget for SingleMatchTable<'_> {
|
|||
|
||||
fn group_row<'a>(app: &'a App, group: &'a LineSet, is_in_view: bool) -> Row<'a> {
|
||||
if is_in_view {
|
||||
let line = &app.lines[group.lines[0]];
|
||||
let line = group.lines[0];
|
||||
|
||||
Row::new([
|
||||
Text::from(line.level.as_str()),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use crate::app::{App, Filter, LogMatch, EMPTY_FILTER};
|
||||
use crate::error::ParseError;
|
||||
use crate::logfile::logline::{FullLogLine, LogLine};
|
||||
use crate::logs::LogIndex;
|
||||
use crate::ui::footer::FooterParams;
|
||||
use crate::ui::input::{PopMode, UiEvent};
|
||||
use crate::ui::table::ScrollbarTableState;
|
||||
|
|
@ -78,7 +77,7 @@ impl PartialEq for MatchListState<'_> {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct MatchState<'a> {
|
||||
pub result: &'a LogMatch,
|
||||
pub result: &'a LogMatch<'a>,
|
||||
pub table_state: ScrollbarTableState,
|
||||
pub previous: Box<UiState<'a>>,
|
||||
pub filter: Filter,
|
||||
|
|
@ -90,7 +89,7 @@ impl<'a> MatchState<'a> {
|
|||
self.table_state.selected()
|
||||
}
|
||||
|
||||
fn enter(self, selected: usize, app: &'a App) -> UiState<'a> {
|
||||
fn enter(self, selected: usize) -> UiState<'a> {
|
||||
let mut table_state = TableState::default();
|
||||
table_state.select(Some(0));
|
||||
|
||||
|
|
@ -102,7 +101,7 @@ impl<'a> MatchState<'a> {
|
|||
self.result
|
||||
.grouped
|
||||
.iter()
|
||||
.filter(|grouped| grouped.matches(app, &self.filter))
|
||||
.filter(|grouped| grouped.matches(&self.filter))
|
||||
.nth(selected - 1)
|
||||
.expect("filtered select out of bounds")
|
||||
};
|
||||
|
|
@ -133,7 +132,7 @@ pub enum GroupedLogGrouping {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct GroupedLogsState<'a> {
|
||||
pub lines: Cow<'a, [LogIndex]>,
|
||||
pub lines: Cow<'a, [&'a LogLine<'a>]>,
|
||||
pub table_state: ScrollbarTableState,
|
||||
pub previous: Box<UiState<'a>>,
|
||||
pub filter: Filter,
|
||||
|
|
@ -146,14 +145,13 @@ impl<'a> GroupedLogsState<'a> {
|
|||
self.table_state.selected()
|
||||
}
|
||||
|
||||
fn get_selected<'b>(&self, selected: usize, app: &'b App<'b>) -> &'b LogLine<'b> {
|
||||
fn get_selected(&self, selected: usize) -> &'a LogLine<'a> {
|
||||
if self.filter.is_empty() {
|
||||
let line = self.lines[selected];
|
||||
&app.lines[line]
|
||||
self.lines[selected]
|
||||
} else {
|
||||
self.lines
|
||||
.iter()
|
||||
.map(|index| &app.lines[*index])
|
||||
.copied()
|
||||
.filter(|line| line.matches(&self.filter))
|
||||
.nth(selected)
|
||||
.expect("filtered select out of bounds")
|
||||
|
|
@ -161,7 +159,7 @@ impl<'a> GroupedLogsState<'a> {
|
|||
}
|
||||
|
||||
fn enter(self, selected: usize, app: &'a App<'a>) -> UiState<'a> {
|
||||
let log = self.get_selected(selected, app);
|
||||
let log = self.get_selected(selected);
|
||||
let raw_line = app.get_source_line(log.line_number).unwrap();
|
||||
let full_line = match parse_line_full(raw_line) {
|
||||
Ok(line) => line,
|
||||
|
|
@ -191,8 +189,8 @@ impl<'a> GroupedLogsState<'a> {
|
|||
}
|
||||
|
||||
fn by_request(self, selected: usize, app: &'a App<'a>) -> UiState<'a> {
|
||||
let log = self.get_selected(selected, app);
|
||||
let lines: Vec<_> = app.line_indices_by_request(&log.request_id).collect();
|
||||
let log = self.get_selected(selected);
|
||||
let lines: Vec<_> = app.lines_by_request(&log.request_id).collect();
|
||||
|
||||
let table_state = ScrollbarTableState::new(lines.len());
|
||||
UiState::GroupedLogs(GroupedLogsState {
|
||||
|
|
@ -234,7 +232,7 @@ pub struct LogState<'a> {
|
|||
|
||||
impl<'a> LogState<'a> {
|
||||
fn by_request(self, app: &'a App<'a>) -> UiState<'a> {
|
||||
let lines: Vec<_> = app.line_indices_by_request(&self.log.request_id).collect();
|
||||
let lines: Vec<_> = app.lines_by_request(&self.log.request_id).collect();
|
||||
|
||||
let table_state = ScrollbarTableState::new(lines.len());
|
||||
UiState::GroupedLogs(GroupedLogsState {
|
||||
|
|
@ -447,9 +445,9 @@ impl<'a> UiState<'a> {
|
|||
}
|
||||
(UiState::Match(state), UiEvent::Select) => {
|
||||
let selected = state.selected();
|
||||
(true, state.enter(selected, app))
|
||||
(true, state.enter(selected))
|
||||
}
|
||||
(UiState::Match(state), UiEvent::Enter(selected)) => (true, state.enter(selected, app)),
|
||||
(UiState::Match(state), UiEvent::Enter(selected)) => (true, state.enter(selected)),
|
||||
(UiState::GroupedLogs(state), UiEvent::Select) => {
|
||||
let selected = state.selected();
|
||||
(true, state.enter(selected, app))
|
||||
|
|
@ -462,7 +460,7 @@ impl<'a> UiState<'a> {
|
|||
let mut table_state = TableState::default();
|
||||
table_state.select(Some(0));
|
||||
|
||||
let line = &app.lines[state.lines[selected]];
|
||||
let line = state.lines[selected];
|
||||
let raw = app.get_source_line(line.line_number).unwrap_or_default();
|
||||
copy_osc(raw);
|
||||
(false, UiState::GroupedLogs(state))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue