Open stefnotch opened 3 months ago
@mladedav Thank you for the excellent review!
To answer your question, yes, it is possible to get the prefix-suffix pattern to work. I had that, and removed it in this commit https://github.com/tokio-rs/tracing/pull/2914/commits/51758ee3e5f83e7857f32e0ae3f60fb2ae18735a That approach basically (ab)used a dummy struct to call the relevant owo-colors functions.
There's also an alternative approach, along the lines of
struct FormatPair<'a, 'b, A, B>(&'a A, &'b B, Style);
impl fmt::Display for FormatPair {
// print the style prefix
// print a
// print b
// print the style suffix
}
I could absolutely add one or more of those approaches, if the extra complexity is worth it.
In case a reviewer is curious, I also tried out an alternative design, where a Style
class also manages the is_ansi
flag.
https://github.com/tokio-rs/tracing/compare/master...stefnotch:tracing:owo-color-alternate-design#diff-8f6911488e5b3b7a50b97db5ab61c50af439560e330a54015889651c63a0dc52
Is there any chance of getting this merged anytime soon? Or would a different direction/dependency be more useful for the tracing project?
Motivation
Fix #2759
Also update docs to fix https://github.com/tokio-rs/tracing/issues/2268
Solution
Replaced nu-ansi-term with owo-colors.
I then ran all the unit tests
cargo test
, and tested thecargo run --example sloggish
andcargo run --example fmt-pretty
examples. I did my best to verify that the output hasn't changed.Questions
During development, rust-analyzer always shows me bogus error messages and I'm not entirely sure what I'm doing wrong. I frequently ended up having to work with
cargo check
and a bit of guesswork.Old fmt-pretty output
New, visually unchanged fmt-pretty output