diff --git a/Cargo.lock b/Cargo.lock index 4588cd06..85f93a73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -600,7 +600,7 @@ checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" [[package]] name = "encstr" -version = "0.29.0-alpha.1" +version = "0.29.0-alpha.2" [[package]] name = "enum-map" @@ -757,7 +757,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hl" -version = "0.29.0-alpha.1" +version = "0.29.0-alpha.2" dependencies = [ "atoi", "bincode", diff --git a/Cargo.toml b/Cargo.toml index b48ee1d3..6072b48b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = [".", "crate/encstr"] [workspace.package] repository = "https://github.com/pamburus/hl" authors = ["Pavel Ivanov "] -version = "0.29.0-alpha.1" +version = "0.29.0-alpha.2" edition = "2021" license = "MIT" diff --git a/src/app.rs b/src/app.rs index 66e9b2a6..6e5c2773 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1060,14 +1060,14 @@ mod tests { #[test] fn test_cat_with_theme() { let input = input( - r#"{"caller":"main.go:539","duration":"15d","level":"info","msg":"No time or size retention was set so using the default time retention","ts":"2023-12-07T20:07:05.949Z"}"#, + r#"{"caller":"main.go:539","duration":"15d","level":"warning","msg":"No time or size retention was set so using the default time retention","ts":"2023-12-07T20:07:05.949Z"}"#, ); let mut output = Vec::new(); let app = App::new(options().with_theme(theme())); app.run(vec![input], &mut output).unwrap(); assert_eq!( std::str::from_utf8(&output).unwrap(), - "\u{1b}[0;2;3m2023-12-07 20:07:05.949 \u{1b}[0;36m|INF| \u{1b}[0;1;39mNo time or size retention was set so using the default time retention \u{1b}[0;32mduration\u{1b}[0;2m=\u{1b}[0;39m15d\u{1b}[0;2;3m @ main.go:539\u{1b}[0m\n", + "\u{1b}[0;2;3m2023-12-07 20:07:05.949 \u{1b}[0;7;33m|WRN|\u{1b}[0m \u{1b}[0;1;39mNo time or size retention was set so using the default time retention \u{1b}[0;32mduration\u{1b}[0;2m=\u{1b}[0;39m15d\u{1b}[0;2;3m @ main.go:539\u{1b}[0m\n", ); } diff --git a/src/formatting.rs b/src/formatting.rs index 204bf9a7..17ef7a27 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -226,6 +226,7 @@ impl RecordFormatter { match value { RawValue::String(value) => { if !value.is_empty() { + s.reset(); s.space(); s.element(Element::Message, |s| { s.batch(|buf| buf.with_auto_trim(|buf| MessageFormatAuto::new(value).format(buf).unwrap())) @@ -913,12 +914,12 @@ mod tests { assert_eq!( &format(&rec), - "\u{1b}[0;2;3m00-01-02 03:04:05.123 \u{1b}[0;36m|\u{1b}[0;95mDBG\u{1b}[0;36m|\u{1b}[0;2;3m \u{1b}[0;2;4mtl: \u{1b}[0;1;39mtm \u{1b}[0;32mk-a\u{1b}[0;2m=\u{1b}[0;33m{ \u{1b}[0;32mva\u{1b}[0;2m=\u{1b}[0;33m{ \u{1b}[0;32mkb\u{1b}[0;2m=\u{1b}[0;94m42 \u{1b}[0;32mkc\u{1b}[0;2m=\u{1b}[0;94m43\u{1b}[0;33m } }\u{1b}[0;2;3m @ tc\u{1b}[0m", + "\u{1b}[0;2;3m00-01-02 03:04:05.123 \u{1b}[0;36m|\u{1b}[0;95mDBG\u{1b}[0;36m|\u{1b}[0;2;3m \u{1b}[0;2;4mtl:\u{1b}[0m \u{1b}[0;1;39mtm \u{1b}[0;32mk-a\u{1b}[0;2m=\u{1b}[0;33m{ \u{1b}[0;32mva\u{1b}[0;2m=\u{1b}[0;33m{ \u{1b}[0;32mkb\u{1b}[0;2m=\u{1b}[0;94m42 \u{1b}[0;32mkc\u{1b}[0;2m=\u{1b}[0;94m43\u{1b}[0;33m } }\u{1b}[0;2;3m @ tc\u{1b}[0m", ); assert_eq!( &formatter().with_flatten(true).format_to_string(&rec), - "\u{1b}[0;2;3m00-01-02 03:04:05.123 \u{1b}[0;36m|\u{1b}[0;95mDBG\u{1b}[0;36m|\u{1b}[0;2;3m \u{1b}[0;2;4mtl: \u{1b}[0;1;39mtm \u{1b}[0;32mk-a.va.kb\u{1b}[0;2m=\u{1b}[0;94m42 \u{1b}[0;32mk-a.va.kc\u{1b}[0;2m=\u{1b}[0;94m43\u{1b}[0;2;3m @ tc\u{1b}[0m", + "\u{1b}[0;2;3m00-01-02 03:04:05.123 \u{1b}[0;36m|\u{1b}[0;95mDBG\u{1b}[0;36m|\u{1b}[0;2;3m \u{1b}[0;2;4mtl:\u{1b}[0m \u{1b}[0;1;39mtm \u{1b}[0;32mk-a.va.kb\u{1b}[0;2m=\u{1b}[0;94m42 \u{1b}[0;32mk-a.va.kc\u{1b}[0;2m=\u{1b}[0;94m43\u{1b}[0;2;3m @ tc\u{1b}[0m", ); } } diff --git a/src/theme.rs b/src/theme.rs index f44fdfcf..2de3ef3b 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -24,6 +24,7 @@ pub trait StylingPush> { fn element R>(&mut self, element: Element, f: F) -> R; fn batch(&mut self, f: F); fn space(&mut self); + fn reset(&mut self); } // --- @@ -238,6 +239,11 @@ impl<'a, B: Push> StylingPush for Styler<'a, B> { self.buf.push(b' '); } + #[inline] + fn reset(&mut self) { + self.reset() + } + #[inline] fn batch(&mut self, f: F) { self.sync();