This commit is contained in:
Robin Appelman 2024-07-24 23:42:08 +02:00
commit e7b70fd00e
6 changed files with 41 additions and 8 deletions

View file

@ -1,13 +1,14 @@
use crate::app::{App, LogMatch};
use crate::logline::LogLine;
use crate::ui::style::{TABLE_HEADER_STYLE, TABLE_SELECTED_STYLE};
use crate::ui::style::{TABLE_HEADER_STYLE, TABLE_SELECTED_STYLE, TIME_FORMAT};
use ratatui::layout::Constraint;
use ratatui::widgets::{Cell, HighlightSpacing, Row, Table};
use time::format_description::well_known::Iso8601;
pub fn single_match<'a>(app: &'a App, matches: &'a LogMatch) -> Table<'a> {
let lines = matches.lines.iter().map(|i| &app.lines[*i]);
let header = ["Level", "App", "Message"]
let header = ["Level", "App", "Message", "Date"]
.into_iter()
.map(Cell::from)
.collect::<Row>()
@ -18,6 +19,7 @@ pub fn single_match<'a>(app: &'a App, matches: &'a LogMatch) -> Table<'a> {
Constraint::Min(10),
Constraint::Min(20),
Constraint::Percentage(100),
Constraint::Min(30),
];
let table = Table::new(lines.map(|line| log_row(line)), widths)
.header(header)
@ -28,8 +30,9 @@ pub fn single_match<'a>(app: &'a App, matches: &'a LogMatch) -> Table<'a> {
fn log_row(line: &LogLine) -> Row {
Row::new([
line.level.as_str(),
line.app.as_str(),
line.message.as_str(),
line.level.as_str().to_string(),
line.app.to_string(),
line.message.clone(),
line.time.format(&Iso8601::<TIME_FORMAT>).unwrap(),
])
}

View file

@ -1,5 +1,11 @@
use ratatui::prelude::Style;
use ratatui::style::palette::tailwind;
use time::format_description::well_known::iso8601::{Config, EncodedConfig, TimePrecision};
pub const TABLE_HEADER_STYLE: Style = Style::new().bg(tailwind::BLACK).fg(tailwind::GREEN.c600);
pub const TABLE_SELECTED_STYLE: Style = Style::new().fg(tailwind::BLACK).bg(tailwind::GREEN.c600);
pub const TIME_FORMAT: EncodedConfig = Config::DEFAULT
.set_time_precision(TimePrecision::Second {
decimal_digits: None,
})
.encode();