mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-04 02:24:11 +02:00
some refactoring
This commit is contained in:
parent
14734ad089
commit
da02bb0329
12 changed files with 237 additions and 111 deletions
|
|
@ -14,9 +14,9 @@ pub fn error_list<'a>(app: &'a App<'a>) -> ScrollbarTable<'a> {
|
|||
.height(1);
|
||||
|
||||
let widths = [Constraint::Percentage(50), Constraint::Percentage(50)];
|
||||
ScrollbarTable::new(app.error_lines.iter().map(error_row), widths).header(header)
|
||||
ScrollbarTable::new(app.error_lines().map(error_row), widths).header(header)
|
||||
}
|
||||
|
||||
fn error_row((line, err): &(String, serde_json::Error)) -> Row {
|
||||
Row::new([Text::from(format!("{err}")), Text::from(line.as_str())])
|
||||
fn error_row<'a>((line, err): (&'a str, &'a serde_json::Error)) -> Row<'a> {
|
||||
Row::new([Text::from(format!("{err}")), Text::from(line)])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ pub fn footer<'a>(app: &App<'a>, params: FooterParams<'a>) -> Table<'a> {
|
|||
[Row::new([
|
||||
Text::from(help(page)),
|
||||
Text::from(format!("{} unmatched items", app.unmatched.count())),
|
||||
Text::from(format!("{} parse errors", app.error_count)),
|
||||
Text::from(format!("{} parse errors", app.error_count())),
|
||||
])],
|
||||
widths,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
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};
|
||||
|
|
@ -11,7 +12,7 @@ use ratatui::text::Text;
|
|||
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
|
||||
|
||||
pub struct GroupedLogs<'a> {
|
||||
lines: &'a [usize],
|
||||
lines: &'a [LogIndex],
|
||||
app: &'a App<'a>,
|
||||
filter: &'a Filter,
|
||||
grouping: GroupedLogGrouping,
|
||||
|
|
@ -19,7 +20,7 @@ pub struct GroupedLogs<'a> {
|
|||
|
||||
pub fn grouped_logs<'a>(
|
||||
app: &'a App<'a>,
|
||||
lines: &'a [usize],
|
||||
lines: &'a [LogIndex],
|
||||
filter: &'a Filter,
|
||||
grouping: GroupedLogGrouping,
|
||||
) -> GroupedLogs<'a> {
|
||||
|
|
@ -38,7 +39,7 @@ impl StatefulWidget for GroupedLogs<'_> {
|
|||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let lines = self.lines.iter().copied().map(|i| &self.app.lines[i]);
|
||||
let lines = self.lines.iter().copied().map(|i| self.app.get_line(i));
|
||||
let line = self
|
||||
.lines
|
||||
.iter()
|
||||
|
|
@ -46,7 +47,7 @@ impl StatefulWidget for GroupedLogs<'_> {
|
|||
.map(|i| &self.app.lines[i])
|
||||
.filter(|line| line.matches(self.filter))
|
||||
.nth(state.selected())
|
||||
.unwrap_or(&self.app.lines[0]);
|
||||
.unwrap_or(self.app.lines.first());
|
||||
|
||||
let par = match self.grouping {
|
||||
GroupedLogGrouping::Message => Paragraph::new(format!(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::app::{App, Filter, GroupedLines, LogMatch};
|
||||
use crate::app::{App, Filter, LineSet, LogMatch};
|
||||
use crate::ui::style::TABLE_HEADER_STYLE;
|
||||
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
|
||||
use ratatui::buffer::Buffer;
|
||||
|
|
@ -78,7 +78,7 @@ impl StatefulWidget for SingleMatchTable<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn group_row<'a>(app: &'a App, group: &'a GroupedLines, is_in_view: bool) -> Row<'a> {
|
||||
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]];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
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;
|
||||
|
|
@ -132,7 +133,7 @@ pub enum GroupedLogGrouping {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct GroupedLogsState<'a> {
|
||||
pub lines: Cow<'a, [usize]>,
|
||||
pub lines: Cow<'a, [LogIndex]>,
|
||||
pub table_state: ScrollbarTableState,
|
||||
pub previous: Box<UiState<'a>>,
|
||||
pub filter: Filter,
|
||||
|
|
@ -161,7 +162,7 @@ impl<'a> GroupedLogsState<'a> {
|
|||
|
||||
fn enter(self, selected: usize, app: &'a App<'a>) -> UiState<'a> {
|
||||
let log = self.get_selected(selected, app);
|
||||
let raw_line = app.get_line(log.index).unwrap();
|
||||
let raw_line = app.get_source_line(log.line_number).unwrap();
|
||||
let full_line = match parse_line_full(raw_line) {
|
||||
Ok(line) => line,
|
||||
Err(err) => {
|
||||
|
|
@ -249,7 +250,7 @@ impl<'a> LogState<'a> {
|
|||
|
||||
impl PartialEq for LogState<'_> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.log.index == other.log.index
|
||||
self.log.line_number == other.log.line_number
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -435,7 +436,7 @@ impl<'a> UiState<'a> {
|
|||
(true, state.enter(selected, app))
|
||||
}
|
||||
(UiState::MatchList(state), UiEvent::Errors) => {
|
||||
let table_state = ScrollbarTableState::new(app.error_lines.len());
|
||||
let table_state = ScrollbarTableState::new(app.error_count());
|
||||
(
|
||||
true,
|
||||
UiState::Errors(ErrorLinesState {
|
||||
|
|
@ -462,12 +463,14 @@ impl<'a> UiState<'a> {
|
|||
table_state.select(Some(0));
|
||||
|
||||
let line = &app.lines[state.lines[selected]];
|
||||
let raw = app.get_line(line.index).unwrap_or_default();
|
||||
let raw = app.get_source_line(line.line_number).unwrap_or_default();
|
||||
copy_osc(raw);
|
||||
(false, UiState::GroupedLogs(state))
|
||||
}
|
||||
(UiState::Log(state), UiEvent::Copy) => {
|
||||
let raw = app.get_line(state.log.index).unwrap_or_default();
|
||||
let raw = app
|
||||
.get_source_line(state.log.line_number)
|
||||
.unwrap_or_default();
|
||||
copy_osc(raw);
|
||||
(false, UiState::Log(state))
|
||||
}
|
||||
|
|
@ -478,9 +481,9 @@ impl<'a> UiState<'a> {
|
|||
(UiState::Log(state), UiEvent::ByRequest) => (true, state.by_request(app)),
|
||||
(UiState::Errors(state), UiEvent::Copy) => {
|
||||
let raw = app
|
||||
.error_lines
|
||||
.get(state.table_state.selected())
|
||||
.map(|(line, _)| line.as_str())
|
||||
.error_lines()
|
||||
.nth(state.table_state.selected())
|
||||
.map(|(line, _)| line)
|
||||
.unwrap_or_default();
|
||||
copy_osc(raw);
|
||||
(false, UiState::Errors(state))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue