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 histogram: TimeGraph,
|
||||
pub sparkline: String,
|
||||
pub all: GroupedLines,
|
||||
pub grouped: Vec<GroupedLines>,
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +52,11 @@ impl LogMatch {
|
|||
}
|
||||
let grouped = group_lines(all_lines, lines.iter().copied());
|
||||
let sparkline = histogram.sparkline::<10>();
|
||||
let all = GroupedLines {
|
||||
sparkline: sparkline.clone(),
|
||||
histogram: histogram.clone(),
|
||||
lines: lines.clone(),
|
||||
};
|
||||
|
||||
LogMatch {
|
||||
result,
|
||||
|
|
@ -58,6 +64,7 @@ impl LogMatch {
|
|||
histogram,
|
||||
sparkline,
|
||||
grouped,
|
||||
all,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use hdrhistogram::Histogram;
|
|||
use std::cmp::max;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TimeGraph {
|
||||
histogram: Histogram<u64>,
|
||||
start: u64,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ use ratatui::text::Text;
|
|||
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
|
||||
|
||||
pub struct GroupedLogs<'a> {
|
||||
line: &'a LogLine<'a>,
|
||||
lines: &'a [usize],
|
||||
app: &'a App<'a>,
|
||||
filter: &'a Filter,
|
||||
|
|
@ -21,13 +20,7 @@ pub fn grouped_logs<'a>(
|
|||
lines: &'a [usize],
|
||||
filter: &'a Filter,
|
||||
) -> GroupedLogs<'a> {
|
||||
let line = &app.lines[lines[0]];
|
||||
GroupedLogs {
|
||||
line,
|
||||
lines,
|
||||
app,
|
||||
filter,
|
||||
}
|
||||
GroupedLogs { lines, app, filter }
|
||||
}
|
||||
|
||||
impl StatefulWidget for GroupedLogs<'_> {
|
||||
|
|
@ -37,24 +30,25 @@ impl StatefulWidget for GroupedLogs<'_> {
|
|||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let line = &self.app.lines[self.lines[state.selected()]];
|
||||
let lines = self.lines.iter().copied().map(|i| &self.app.lines[i]);
|
||||
|
||||
let par = Paragraph::new(format!(
|
||||
"{}{}{}\n\n{} from {} - Nextcloud {}",
|
||||
self.line
|
||||
line
|
||||
.exception
|
||||
.as_ref()
|
||||
.map(|e| e.exception.as_ref())
|
||||
.unwrap_or_default(),
|
||||
if self.line.exception.is_some() {
|
||||
if line.exception.is_some() {
|
||||
":\n"
|
||||
} else {
|
||||
""
|
||||
},
|
||||
self.line.message,
|
||||
self.line.level.as_str(),
|
||||
self.line.app,
|
||||
self.line.version,
|
||||
line.message,
|
||||
line.level.as_str(),
|
||||
line.app,
|
||||
line.version,
|
||||
))
|
||||
.wrap(Wrap::default());
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use crate::ui::table::ScrollbarTable;
|
|||
use ratatui::layout::Constraint;
|
||||
use ratatui::text::Text;
|
||||
use ratatui::widgets::{Cell, Row};
|
||||
use std::iter::once;
|
||||
|
||||
pub fn grouped_lines<'a>(
|
||||
app: &'a App<'a>,
|
||||
|
|
@ -32,10 +33,19 @@ pub fn grouped_lines<'a>(
|
|||
Constraint::Min(10),
|
||||
];
|
||||
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
|
||||
.iter()
|
||||
.filter(|group| group.matches(app, filter))
|
||||
.map(|group| group_row(app, group)),
|
||||
),
|
||||
widths,
|
||||
)
|
||||
.header(header)
|
||||
|
|
|
|||
|
|
@ -88,14 +88,16 @@ impl<'a> MatchState<'a> {
|
|||
let mut table_state = TableState::default();
|
||||
table_state.select(Some(0));
|
||||
|
||||
let selected_line = if self.filter.is_empty() {
|
||||
&self.result.grouped[selected]
|
||||
let selected_line = if selected == 0 {
|
||||
&self.result.all
|
||||
} else if self.filter.is_empty() {
|
||||
&self.result.grouped[selected - 1]
|
||||
} else {
|
||||
self.result
|
||||
.grouped
|
||||
.iter()
|
||||
.filter(|grouped| grouped.matches(app, &self.filter))
|
||||
.nth(selected)
|
||||
.nth(selected - 1)
|
||||
.expect("filtered select out of bounds")
|
||||
};
|
||||
let lines = selected_line.lines.as_slice();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue