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"
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]]
name = "logparse"
version = "0.1.0"
dependencies = [
"insta",
"proptest",
"proptest-derive",
"winnow",
]
[[package]]
name = "loom"
version = "0.7.2"
@ -1416,12 +1426,10 @@ dependencies = [
"clap",
"crossterm",
"dumpster",
"insta",
"itertools",
"jiff",
"logparse",
"nix 0.31.1",
"proptest",
"proptest-derive",
"ratatui",
"ratatui-themes",
"regex",
@ -1429,7 +1437,6 @@ dependencies = [
"serde_json",
"thiserror 2.0.18",
"tui-widget-list",
"winnow",
]
[[package]]

View file

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

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,
};
pub mod format_debug_output;
mod tui;
use clap::{Parser, Subcommand, ValueEnum, builder::PossibleValue};

View file

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