mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
add 'All Lines' to match view
This commit is contained in:
parent
64cea44dbe
commit
4d9719345f
5 changed files with 35 additions and 21 deletions
|
|
@ -38,6 +38,7 @@ pub struct LogMatch {
|
||||||
pub lines: Vec<usize>,
|
pub lines: Vec<usize>,
|
||||||
pub histogram: TimeGraph,
|
pub histogram: TimeGraph,
|
||||||
pub sparkline: String,
|
pub sparkline: String,
|
||||||
|
pub all: GroupedLines,
|
||||||
pub grouped: Vec<GroupedLines>,
|
pub grouped: Vec<GroupedLines>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,6 +52,11 @@ impl LogMatch {
|
||||||
}
|
}
|
||||||
let grouped = group_lines(all_lines, lines.iter().copied());
|
let grouped = group_lines(all_lines, lines.iter().copied());
|
||||||
let sparkline = histogram.sparkline::<10>();
|
let sparkline = histogram.sparkline::<10>();
|
||||||
|
let all = GroupedLines {
|
||||||
|
sparkline: sparkline.clone(),
|
||||||
|
histogram: histogram.clone(),
|
||||||
|
lines: lines.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
LogMatch {
|
LogMatch {
|
||||||
result,
|
result,
|
||||||
|
|
@ -58,6 +64,7 @@ impl LogMatch {
|
||||||
histogram,
|
histogram,
|
||||||
sparkline,
|
sparkline,
|
||||||
grouped,
|
grouped,
|
||||||
|
all,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use hdrhistogram::Histogram;
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct TimeGraph {
|
pub struct TimeGraph {
|
||||||
histogram: Histogram<u64>,
|
histogram: Histogram<u64>,
|
||||||
start: u64,
|
start: u64,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ use ratatui::text::Text;
|
||||||
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
|
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
|
||||||
|
|
||||||
pub struct GroupedLogs<'a> {
|
pub struct GroupedLogs<'a> {
|
||||||
line: &'a LogLine<'a>,
|
|
||||||
lines: &'a [usize],
|
lines: &'a [usize],
|
||||||
app: &'a App<'a>,
|
app: &'a App<'a>,
|
||||||
filter: &'a Filter,
|
filter: &'a Filter,
|
||||||
|
|
@ -21,13 +20,7 @@ pub fn grouped_logs<'a>(
|
||||||
lines: &'a [usize],
|
lines: &'a [usize],
|
||||||
filter: &'a Filter,
|
filter: &'a Filter,
|
||||||
) -> GroupedLogs<'a> {
|
) -> GroupedLogs<'a> {
|
||||||
let line = &app.lines[lines[0]];
|
GroupedLogs { lines, app, filter }
|
||||||
GroupedLogs {
|
|
||||||
line,
|
|
||||||
lines,
|
|
||||||
app,
|
|
||||||
filter,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StatefulWidget for GroupedLogs<'_> {
|
impl StatefulWidget for GroupedLogs<'_> {
|
||||||
|
|
@ -37,24 +30,25 @@ impl StatefulWidget for GroupedLogs<'_> {
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
|
let line = &self.app.lines[self.lines[state.selected()]];
|
||||||
let lines = self.lines.iter().copied().map(|i| &self.app.lines[i]);
|
let lines = self.lines.iter().copied().map(|i| &self.app.lines[i]);
|
||||||
|
|
||||||
let par = Paragraph::new(format!(
|
let par = Paragraph::new(format!(
|
||||||
"{}{}{}\n\n{} from {} - Nextcloud {}",
|
"{}{}{}\n\n{} from {} - Nextcloud {}",
|
||||||
self.line
|
line
|
||||||
.exception
|
.exception
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|e| e.exception.as_ref())
|
.map(|e| e.exception.as_ref())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
if self.line.exception.is_some() {
|
if line.exception.is_some() {
|
||||||
":\n"
|
":\n"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
},
|
},
|
||||||
self.line.message,
|
line.message,
|
||||||
self.line.level.as_str(),
|
line.level.as_str(),
|
||||||
self.line.app,
|
line.app,
|
||||||
self.line.version,
|
line.version,
|
||||||
))
|
))
|
||||||
.wrap(Wrap::default());
|
.wrap(Wrap::default());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::ui::table::ScrollbarTable;
|
||||||
use ratatui::layout::Constraint;
|
use ratatui::layout::Constraint;
|
||||||
use ratatui::text::Text;
|
use ratatui::text::Text;
|
||||||
use ratatui::widgets::{Cell, Row};
|
use ratatui::widgets::{Cell, Row};
|
||||||
|
use std::iter::once;
|
||||||
|
|
||||||
pub fn grouped_lines<'a>(
|
pub fn grouped_lines<'a>(
|
||||||
app: &'a App<'a>,
|
app: &'a App<'a>,
|
||||||
|
|
@ -32,10 +33,19 @@ pub fn grouped_lines<'a>(
|
||||||
Constraint::Min(10),
|
Constraint::Min(10),
|
||||||
];
|
];
|
||||||
ScrollbarTable::new(
|
ScrollbarTable::new(
|
||||||
|
once(Row::new([
|
||||||
|
Text::from("All lines"),
|
||||||
|
Text::from(""),
|
||||||
|
Text::from(""),
|
||||||
|
Text::from(log_match.sparkline.as_str()),
|
||||||
|
Text::from(log_match.lines.len().to_string()),
|
||||||
|
]))
|
||||||
|
.chain(
|
||||||
grouped
|
grouped
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|group| group.matches(app, filter))
|
.filter(|group| group.matches(app, filter))
|
||||||
.map(|group| group_row(app, group)),
|
.map(|group| group_row(app, group)),
|
||||||
|
),
|
||||||
widths,
|
widths,
|
||||||
)
|
)
|
||||||
.header(header)
|
.header(header)
|
||||||
|
|
|
||||||
|
|
@ -88,14 +88,16 @@ impl<'a> MatchState<'a> {
|
||||||
let mut table_state = TableState::default();
|
let mut table_state = TableState::default();
|
||||||
table_state.select(Some(0));
|
table_state.select(Some(0));
|
||||||
|
|
||||||
let selected_line = if self.filter.is_empty() {
|
let selected_line = if selected == 0 {
|
||||||
&self.result.grouped[selected]
|
&self.result.all
|
||||||
|
} else if self.filter.is_empty() {
|
||||||
|
&self.result.grouped[selected - 1]
|
||||||
} else {
|
} else {
|
||||||
self.result
|
self.result
|
||||||
.grouped
|
.grouped
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|grouped| grouped.matches(app, &self.filter))
|
.filter(|grouped| grouped.matches(app, &self.filter))
|
||||||
.nth(selected)
|
.nth(selected - 1)
|
||||||
.expect("filtered select out of bounds")
|
.expect("filtered select out of bounds")
|
||||||
};
|
};
|
||||||
let lines = selected_line.lines.as_slice();
|
let lines = selected_line.lines.as_slice();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue