mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
lazy single_match table
This commit is contained in:
parent
8299a90578
commit
b8af91acd7
1 changed files with 83 additions and 50 deletions
|
|
@ -1,7 +1,11 @@
|
|||
use crate::app::{App, Filter, GroupedLines, LogMatch};
|
||||
use crate::ui::grouped_logs::GroupedLogs;
|
||||
use crate::ui::state::GroupedLogGrouping;
|
||||
use crate::ui::style::TABLE_HEADER_STYLE;
|
||||
use crate::ui::table::ScrollbarTable;
|
||||
use ratatui::layout::Constraint;
|
||||
use crate::ui::table::{ScrollbarTable, ScrollbarTableState};
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::{Constraint, Rect};
|
||||
use ratatui::prelude::StatefulWidget;
|
||||
use ratatui::text::Text;
|
||||
use ratatui::widgets::{Cell, Row};
|
||||
use std::iter::once;
|
||||
|
|
@ -9,9 +13,29 @@ use std::iter::once;
|
|||
pub fn grouped_lines<'a>(
|
||||
app: &'a App<'a>,
|
||||
log_match: &'a LogMatch,
|
||||
filter: &Filter,
|
||||
) -> ScrollbarTable<'a> {
|
||||
let grouped = &log_match.grouped;
|
||||
filter: &'a Filter,
|
||||
) -> SingleMatchTable<'a> {
|
||||
SingleMatchTable {
|
||||
app,
|
||||
log_match,
|
||||
filter
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SingleMatchTable<'a> {
|
||||
app: &'a App<'a>,
|
||||
log_match: &'a LogMatch,
|
||||
filter: &'a Filter,
|
||||
}
|
||||
|
||||
impl StatefulWidget for SingleMatchTable<'_> {
|
||||
type State = ScrollbarTableState;
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let grouped = &self.log_match.grouped;
|
||||
let header = [
|
||||
Text::from("Level"),
|
||||
Text::from("App"),
|
||||
|
|
@ -32,26 +56,32 @@ pub fn grouped_lines<'a>(
|
|||
Constraint::Length(10),
|
||||
Constraint::Min(10),
|
||||
];
|
||||
ScrollbarTable::new(
|
||||
let table = ScrollbarTable::new(
|
||||
once(Row::new([
|
||||
Text::from("All lines"),
|
||||
Text::from(""),
|
||||
Text::from(""),
|
||||
Text::from(log_match.sparkline(app)),
|
||||
Text::from(log_match.count().to_string()),
|
||||
Text::from(self.log_match.sparkline(self.app)),
|
||||
Text::from(self.log_match.count().to_string()),
|
||||
]))
|
||||
.chain(
|
||||
grouped
|
||||
.iter()
|
||||
.filter(|group| group.matches(app, filter))
|
||||
.map(|group| group_row(app, group)),
|
||||
.filter(|group| group.matches(self.app, self.filter))
|
||||
.enumerate()
|
||||
.map(|(i, group)| {
|
||||
group_row(self.app, group, i.abs_diff(state.selected()) < 100)
|
||||
}),
|
||||
),
|
||||
widths,
|
||||
)
|
||||
.header(header)
|
||||
.header(header);
|
||||
table.render(area, buf, state);
|
||||
}
|
||||
}
|
||||
|
||||
fn group_row<'a>(app: &'a App, group: &'a GroupedLines) -> Row<'a> {
|
||||
fn group_row<'a>(app: &'a App, group: &'a GroupedLines, is_in_view: bool) -> Row<'a> {
|
||||
if is_in_view {
|
||||
let line = &app.lines[group.lines[0]];
|
||||
|
||||
Row::new([
|
||||
|
|
@ -61,4 +91,7 @@ fn group_row<'a>(app: &'a App, group: &'a GroupedLines) -> Row<'a> {
|
|||
Text::from(group.sparkline(app)),
|
||||
Text::from(group.len().to_string()),
|
||||
])
|
||||
} else {
|
||||
Row::default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue