diff --git a/Cargo.lock b/Cargo.lock index 546d8830..342b5b99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -785,7 +785,7 @@ dependencies = [ [[package]] name = "hl" -version = "0.15.1" +version = "0.15.2" dependencies = [ "anyhow", "atoi", diff --git a/Cargo.toml b/Cargo.toml index b39e7b5b..6829b889 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ categories = ["command-line-utilities"] description = "Utility for viewing json-formatted log files." keywords = ["cli", "human", "log"] name = "hl" -version = "0.15.1" +version = "0.15.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/benches/go/go.mod b/benches/go/go.mod new file mode 100644 index 00000000..64d58b2a --- /dev/null +++ b/benches/go/go.mod @@ -0,0 +1,3 @@ +module github.com/pamburus/hl/benches/go + +go 1.20 diff --git a/benches/parse-and-format.rs b/benches/parse-and-format.rs index 2b2bf951..b6178092 100644 --- a/benches/parse-and-format.rs +++ b/benches/parse-and-format.rs @@ -9,7 +9,8 @@ use criterion::{criterion_group, criterion_main, Criterion}; // local imports use hl::{ timezone::Tz, DateTimeFormatter, Filter, IncludeExcludeKeyFilter, LinuxDateFormat, Parser, - ParserSettings, RecordFormatter, SegmentProcesor, Settings, Theme, + ParserSettings, RecordFormatter, SegmentProcessor, Settings, Theme, + settings, }; // --- @@ -29,9 +30,10 @@ fn benchmark(c: &mut Criterion) { ), false, Arc::new(IncludeExcludeKeyFilter::default()), + settings::Formatting::default(), ); let filter = Filter::default(); - let mut processor = SegmentProcesor::new(&parser, &mut formatter, &filter); + let mut processor = SegmentProcessor::new(&parser, &mut formatter, &filter); let mut buf = Vec::new(); b.iter(|| { processor.run(record, &mut buf); diff --git a/src/app.rs b/src/app.rs index b95ceaf5..72e9ada7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -94,7 +94,7 @@ impl App { self.options.formatting.clone(), ) .with_field_unescaping(!self.options.raw_fields); - let mut processor = SegmentProcesor::new(&parser, &mut formatter, &self.options.filter); + let mut processor = SegmentProcessor::new(&parser, &mut formatter, &self.options.filter); for segment in rxi.iter() { match segment { Segment::Complete(segment) => { @@ -144,13 +144,13 @@ impl App { // --- -pub struct SegmentProcesor<'a> { +pub struct SegmentProcessor<'a> { parser: &'a Parser, formatter: &'a mut RecordFormatter, filter: &'a Filter, } -impl<'a> SegmentProcesor<'a> { +impl<'a> SegmentProcessor<'a> { pub fn new(parser: &'a Parser, formatter: &'a mut RecordFormatter, filter: &'a Filter) -> Self { Self { parser, diff --git a/src/eseq.rs b/src/eseq.rs index f1abf79e..18735a51 100644 --- a/src/eseq.rs +++ b/src/eseq.rs @@ -14,7 +14,7 @@ pub enum Mode { SlowBlink, RapidBlink, Reverse, - Conseal, + Conceal, CrossedOut, } diff --git a/src/lib.rs b/src/lib.rs index 34d15ec0..7a7f2237 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ mod scanning; pub mod signal; // public uses -pub use app::{App, FieldOptions, Options, SegmentProcesor}; +pub use app::{App, FieldOptions, Options, SegmentProcessor}; pub use datefmt::{DateTimeFormatter, LinuxDateFormat}; pub use filtering::DefaultNormalizing; pub use formatting::RecordFormatter; diff --git a/src/model.rs b/src/model.rs index f9159478..d2962d3f 100644 --- a/src/model.rs +++ b/src/model.rs @@ -482,20 +482,26 @@ pub struct FieldFilter { impl FieldFilter { fn parse(text: &str) -> Result { - let mut parts = text.split('='); - match (parts.next(), parts.next()) { - (Some(key), Some(value)) => { - let (key, match_policy, op) = Self::parse_mp_op(key, value)?; - let flat_key = key.as_bytes().iter().position(|&x| x == b'.').is_none(); - Ok(Self { - key: key.into(), - match_policy, - op, - flat_key, - }) - } - _ => Err(Error::WrongFieldFilter(text.into())), + let parse = |key, value| { + let (key, match_policy, op) = Self::parse_mp_op(key, value)?; + let flat_key = key.as_bytes().iter().position(|&x| x == b'.').is_none(); + Ok(Self { + key: key.into(), + match_policy, + op, + flat_key, + }) + }; + + if let Some(index) = text.find('=') { + return parse(&text[0..index], &text[index+1..]); } + + if let Some(index) = text.find(':') { + return parse(&text[0..index], &text[index+1..]); + } + + Err(Error::WrongFieldFilter(text.into())) } fn parse_mp_op<'k>( diff --git a/src/settings.rs b/src/settings.rs index f1c8091a..678fb613 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -117,7 +117,7 @@ pub struct Field { // --- -#[derive(Debug, Deserialize, Clone)] +#[derive(Clone, Debug, Default, Deserialize)] pub struct Formatting { pub punctuation: Punctuation, } diff --git a/src/theme.rs b/src/theme.rs index a1112534..19b37fbf 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -162,7 +162,7 @@ impl From<&themecfg::Style> for Style { codes.push( match mode { themecfg::Mode::Bold => Mode::Bold, - themecfg::Mode::Conseal => Mode::Conseal, + themecfg::Mode::Conceal => Mode::Conceal, themecfg::Mode::CrossedOut => Mode::CrossedOut, themecfg::Mode::Faint => Mode::Faint, themecfg::Mode::Italic => Mode::Italic, diff --git a/src/themecfg.rs b/src/themecfg.rs index 4191dcdf..933c9d12 100644 --- a/src/themecfg.rs +++ b/src/themecfg.rs @@ -222,7 +222,7 @@ pub enum Mode { SlowBlink, RapidBlink, Reverse, - Conseal, + Conceal, CrossedOut, }