mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
handle more date formats
This commit is contained in:
parent
5f24ab45c2
commit
730b7b8c7a
6 changed files with 26 additions and 16 deletions
|
|
@ -24,7 +24,7 @@ pub struct LogLine<'a> {
|
|||
pub level: LogLevel,
|
||||
pub message: Cow<'a, str>,
|
||||
pub exception: Option<Exception<'a>>,
|
||||
pub app: &'a str,
|
||||
pub app: Cow<'a, str>,
|
||||
#[serde(with = "date")]
|
||||
pub time: OffsetDateTime,
|
||||
}
|
||||
|
|
@ -40,9 +40,12 @@ mod date {
|
|||
use time::parsing::Parsable;
|
||||
use time::{OffsetDateTime, PrimitiveDateTime};
|
||||
|
||||
const FORMATS: &[&[BorrowedFormatItem]] = &[format_description!(
|
||||
"[year]-[month]-[day] [hour]:[minute]:[second]"
|
||||
)];
|
||||
const FORMATS: &[&[BorrowedFormatItem]] = &[
|
||||
format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"),
|
||||
format_description!(
|
||||
"[month repr:long case_sensitive:false] [day], [year] [hour]:[minute]:[second]"
|
||||
),
|
||||
];
|
||||
|
||||
fn try_format(str: &str, format: &(impl Parsable + ?Sized)) -> Option<OffsetDateTime> {
|
||||
if let Ok(date) = OffsetDateTime::parse(str, format) {
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ fn test_matcher() {
|
|||
Some(MatchResult::Single(0)),
|
||||
matcher.match_log(&LogLine {
|
||||
version: "29",
|
||||
app: "core",
|
||||
app: "core".into(),
|
||||
level: LogLevel::Error,
|
||||
message: "Not allowed to rename a shared album".into(),
|
||||
exception: None,
|
||||
|
|
@ -339,7 +339,7 @@ fn test_matcher() {
|
|||
Some(MatchResult::List(vec![3, 4])),
|
||||
matcher.match_log(&LogLine {
|
||||
version: "29",
|
||||
app: "core",
|
||||
app: "core".into(),
|
||||
level: LogLevel::Error,
|
||||
message: "Not allowed to rename an album".into(),
|
||||
exception: None,
|
||||
|
|
@ -351,7 +351,7 @@ fn test_matcher() {
|
|||
Some(MatchResult::Single(1)),
|
||||
matcher.match_log(&LogLine {
|
||||
version: "29",
|
||||
app: "core",
|
||||
app: "core".into(),
|
||||
level: LogLevel::Error,
|
||||
message: "You are not allowed to edit link shares that you don't own".into(),
|
||||
exception: None,
|
||||
|
|
@ -363,7 +363,7 @@ fn test_matcher() {
|
|||
None,
|
||||
matcher.match_log(&LogLine {
|
||||
version: "29",
|
||||
app: "core",
|
||||
app: "core".into(),
|
||||
level: LogLevel::Info,
|
||||
message: "You are not allowed to edit link shares that you don't own".into(),
|
||||
exception: None,
|
||||
|
|
@ -376,7 +376,7 @@ fn test_matcher() {
|
|||
matcher.match_log(
|
||||
&LogLine {
|
||||
version: "29",
|
||||
app: "core",
|
||||
app: "core".into(),
|
||||
level: LogLevel::Error,
|
||||
message: "Unsupported query value for mimetype: %/text, only values in the format \"mime/type\" or \"mime/%\" are supported".into(),
|
||||
exception: None,
|
||||
|
|
@ -390,7 +390,7 @@ fn test_matcher() {
|
|||
matcher.match_log(
|
||||
&LogLine {
|
||||
version: "29",
|
||||
app: "core",
|
||||
app: "core".into(),
|
||||
level: LogLevel::Error,
|
||||
message: "Unsupported query value for mimetype: %/text, only values in the format \"mime/type\" or \"mime/%\" are supported".into(),
|
||||
exception: Some(Exception {
|
||||
|
|
@ -408,7 +408,7 @@ fn test_matcher() {
|
|||
Some(MatchResult::Single(5)),
|
||||
matcher.match_log(&LogLine {
|
||||
version: "29",
|
||||
app: "core",
|
||||
app: "core".into(),
|
||||
level: LogLevel::Error,
|
||||
message: "Not allowed to rename 'foo to' to to2".into(),
|
||||
exception: None,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub fn raw_logs<'a>(app: &'a App<'a>, lines: &[usize]) -> ScrollbarTable<'a> {
|
|||
fn log_row<'a>(line: &'a LogLine<'a>) -> Row<'a> {
|
||||
Row::new([
|
||||
Text::from(line.level.as_str()),
|
||||
Text::from(line.app),
|
||||
Text::from(line.app.as_ref()),
|
||||
Text::from(line.display()),
|
||||
Text::from(format_time(line.time)).alignment(Alignment::Right),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ fn group_row<'a>(app: &'a App, group: &'a GroupedLines) -> Row<'a> {
|
|||
|
||||
Row::new([
|
||||
Text::from(line.level.as_str()),
|
||||
Text::from(line.app),
|
||||
Text::from(line.app.as_ref()),
|
||||
Text::from(line.display()),
|
||||
Text::from(group.sparkline.as_str()),
|
||||
Text::from(group.len().to_string()),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::iter::once;
|
||||
use crate::app::{App, LogMatch};
|
||||
use crate::logline::{FullLogLine, LogLine};
|
||||
use crate::ui::table::ScrollbarTableState;
|
||||
|
|
@ -6,6 +5,7 @@ use crate::ui::UI_HEADER_SIZE;
|
|||
use crate::{copy_osc, parse_line_full};
|
||||
use derive_more::From;
|
||||
use ratatui::widgets::TableState;
|
||||
use std::iter::once;
|
||||
|
||||
#[derive(Clone, From, PartialEq)]
|
||||
pub enum UiState<'a> {
|
||||
|
|
@ -213,7 +213,11 @@ impl<'a> UiState<'a> {
|
|||
UiState::MatchList(MatchListState { app, .. }) => {
|
||||
let mut total_height = 0;
|
||||
let match_row_counts = app.matches.iter().map(|m| m.row_count());
|
||||
for (index, row_count) in once(1).chain(match_row_counts).chain(once(1)).enumerate().skip(self.scroll_offset())
|
||||
for (index, row_count) in once(1)
|
||||
.chain(match_row_counts)
|
||||
.chain(once(1))
|
||||
.enumerate()
|
||||
.skip(self.scroll_offset())
|
||||
{
|
||||
if total_height > row {
|
||||
return index - 1;
|
||||
|
|
|
|||
|
|
@ -102,7 +102,10 @@ impl ScrollbarTableState {
|
|||
|
||||
pub fn scroll(&mut self, step: isize) {
|
||||
*self.table.offset_mut() = self.table.offset().saturating_add_signed(step);
|
||||
let selected = self.selected().saturating_add_signed(step).min(self.count - 1);
|
||||
let selected = self
|
||||
.selected()
|
||||
.saturating_add_signed(step)
|
||||
.min(self.count - 1);
|
||||
self.table.select(Some(selected));
|
||||
self.scrollbar = self.scrollbar.position(selected);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue