factor out crate

This commit is contained in:
Jana Dönszelmann 2026-04-02 08:31:58 +02:00
parent bb8fa818d2
commit af09bcd403
No known key found for this signature in database
11 changed files with 43 additions and 22 deletions

15
Cargo.lock generated
View file

@ -819,6 +819,16 @@ version = "0.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]]
name = "logparse"
version = "0.1.0"
dependencies = [
"insta",
"proptest",
"proptest-derive",
"winnow",
]
[[package]] [[package]]
name = "loom" name = "loom"
version = "0.7.2" version = "0.7.2"
@ -1416,12 +1426,10 @@ dependencies = [
"clap", "clap",
"crossterm", "crossterm",
"dumpster", "dumpster",
"insta",
"itertools", "itertools",
"jiff", "jiff",
"logparse",
"nix 0.31.1", "nix 0.31.1",
"proptest",
"proptest-derive",
"ratatui", "ratatui",
"ratatui-themes", "ratatui-themes",
"regex", "regex",
@ -1429,7 +1437,6 @@ dependencies = [
"serde_json", "serde_json",
"thiserror 2.0.18", "thiserror 2.0.18",
"tui-widget-list", "tui-widget-list",
"winnow",
] ]
[[package]] [[package]]

View file

@ -7,6 +7,10 @@ edition = "2024"
name = "lv" name = "lv"
path = "./src/main.rs" path = "./src/main.rs"
[workspace]
members = [".", "./logparse/"]
default-members = [".", "./logparse/"]
[dependencies] [dependencies]
clap = {version="4.5", features=["derive", "string"]} clap = {version="4.5", features=["derive", "string"]}
jiff = {version = "0.2", features = ["serde"]} jiff = {version = "0.2", features = ["serde"]}
@ -21,7 +25,4 @@ nix = {version = "0.31", features = ["process", "signal"]}
regex = "1" regex = "1"
crossterm = "*" crossterm = "*"
dumpster = "2.1" dumpster = "2.1"
winnow = {version="1", features=["parser"]} logparse = {path = "./logparse/", version="0.1.0"}
proptest = "1"
proptest-derive = "0.8"
insta = "1"

16
logparse/Cargo.toml Normal file
View file

@ -0,0 +1,16 @@
[package]
name = "logparse"
version = "0.1.0"
edition = "2024"
description = "parse arbitrary messages containing rust-like debug output to syntax highlight them"
authors = ["Jana Dönszelmann <cratesio@donsz.nl>"]
license = "MIT OR Apache-2.0"
documentation = "https://docs.rs/logparse"
homepage = "https://git.donsz.nl/jana/logviewer"
repository = "https://git.donsz.nl/jana/logviewer"
[dependencies]
winnow = {version="1", features=["parser"]}
proptest = "1"
proptest-derive = "0.8"
insta = "1"

View file

@ -9,7 +9,6 @@ use std::{
str::FromStr, str::FromStr,
}; };
pub mod format_debug_output;
mod tui; mod tui;
use clap::{Parser, Subcommand, ValueEnum, builder::PossibleValue}; use clap::{Parser, Subcommand, ValueEnum, builder::PossibleValue};

View file

@ -2,10 +2,8 @@ use std::borrow::Cow;
use ratatui::text::{Line, Span, Text}; use ratatui::text::{Line, Span, Text};
use crate::{ use crate::tui::widgets::styled::Styled;
format_debug_output::{Config, SpanKind, into_spans, parse_input}, use logparse::{self as lp, Config, SpanKind, into_spans, parse_input};
tui::widgets::styled::Styled,
};
#[derive(Debug)] #[derive(Debug)]
pub enum Highlighted { pub enum Highlighted {
@ -45,7 +43,7 @@ impl LineText {
#[derive(Debug)] #[derive(Debug)]
pub struct HighlightedSpan<'a> { pub struct HighlightedSpan<'a> {
span: crate::format_debug_output::Span<'a>, span: lp::Span<'a>,
highlighted: bool, highlighted: bool,
} }
@ -62,7 +60,7 @@ fn cow_split_at<'a>(inp: Cow<'a, str>, offset: usize) -> (Cow<'a, str>, Cow<'a,
} }
} }
fn span_len(span: &crate::format_debug_output::Span<'_>) -> usize { fn span_len(span: &lp::Span<'_>) -> usize {
match span.kind { match span.kind {
SpanKind::Space(n) => n, SpanKind::Space(n) => n,
_ => span.text.len(), _ => span.text.len(),
@ -70,7 +68,7 @@ fn span_len(span: &crate::format_debug_output::Span<'_>) -> usize {
} }
fn highlight_spans<'a>( fn highlight_spans<'a>(
i: impl Iterator<Item = crate::format_debug_output::Span<'a>>, i: impl Iterator<Item = lp::Span<'a>>,
start: usize, start: usize,
end: usize, end: usize,
) -> impl Iterator<Item = HighlightedSpan<'a>> { ) -> impl Iterator<Item = HighlightedSpan<'a>> {
@ -86,7 +84,7 @@ fn highlight_spans<'a>(
}]; }];
} }
let crate::format_debug_output::Span { text, kind } = span; let lp::Span { text, kind } = span;
let mut res = Vec::new(); let mut res = Vec::new();
@ -95,7 +93,7 @@ fn highlight_spans<'a>(
let until_start = start - curr_offset; let until_start = start - curr_offset;
let (before, after) = cow_split_at(text, until_start); let (before, after) = cow_split_at(text, until_start);
let before_span = crate::format_debug_output::Span { kind, text: before }; let before_span = lp::Span { kind, text: before };
let l = span_len(&before_span); let l = span_len(&before_span);
if l != 0 { if l != 0 {
@ -118,7 +116,7 @@ fn highlight_spans<'a>(
// entirely within // entirely within
if curr_offset + text.len() <= end { if curr_offset + text.len() <= end {
let span = crate::format_debug_output::Span { kind, text }; let span = lp::Span { kind, text };
curr_offset += span_len(&span); curr_offset += span_len(&span);
res.push(HighlightedSpan { res.push(HighlightedSpan {
span, span,
@ -132,7 +130,7 @@ fn highlight_spans<'a>(
let until_start = end - curr_offset; let until_start = end - curr_offset;
let (before, after) = cow_split_at(text, until_start); let (before, after) = cow_split_at(text, until_start);
let before_span = crate::format_debug_output::Span { kind, text: before }; let before_span = lp::Span { kind, text: before };
curr_offset += span_len(&before_span); curr_offset += span_len(&before_span);
res.push(HighlightedSpan { res.push(HighlightedSpan {
@ -149,7 +147,7 @@ fn highlight_spans<'a>(
return res; return res;
} }
let after = crate::format_debug_output::Span { kind, text }; let after = lp::Span { kind, text };
curr_offset += span_len(&after); curr_offset += span_len(&after);
res.push(HighlightedSpan { res.push(HighlightedSpan {
@ -201,7 +199,7 @@ impl Into<Line<'static>> for Styled<'_, LineText> {
.into_iter() .into_iter()
.map( .map(
|HighlightedSpan { |HighlightedSpan {
span: crate::format_debug_output::Span { text, kind }, span: lp::Span { text, kind },
highlighted, highlighted,
}| { }| {
let span = Span::from(text.into_owned()); let span = Span::from(text.into_owned());