From 730b0a096b121e4732f9e69a0132f1ccd4dbd9ed Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Jan 2024 11:15:32 -0600 Subject: [PATCH] fix(fmt): Allow styling on the `Pipe` Fixes #274 --- src/fmt/writer/buffer.rs | 4 ++++ src/fmt/writer/mod.rs | 7 +------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/fmt/writer/buffer.rs b/src/fmt/writer/buffer.rs index fe983a0..89ad912 100644 --- a/src/fmt/writer/buffer.rs +++ b/src/fmt/writer/buffer.rs @@ -83,6 +83,10 @@ impl BufferWriter { eprint!("{}", buf); } WritableTarget::Pipe(pipe) => { + #[cfg(feature = "color")] + let buf = adapt(buf, self.write_style)?; + #[cfg(feature = "color")] + let buf = &buf; let mut stream = pipe.lock().unwrap(); stream.write_all(buf)?; stream.flush()?; diff --git a/src/fmt/writer/mod.rs b/src/fmt/writer/mod.rs index 545d642..a3e6606 100644 --- a/src/fmt/writer/mod.rs +++ b/src/fmt/writer/mod.rs @@ -129,16 +129,11 @@ impl Builder { match &self.target { Target::Stdout => anstream::AutoStream::choice(&std::io::stdout()).into(), Target::Stderr => anstream::AutoStream::choice(&std::io::stderr()).into(), - Target::Pipe(_) => WriteStyle::Never, + Target::Pipe(_) => color_choice, } } else { color_choice }; - let color_choice = match &self.target { - Target::Stdout => color_choice, - Target::Stderr => color_choice, - Target::Pipe(_) => WriteStyle::Never, - }; let color_choice = if color_choice == WriteStyle::Auto { WriteStyle::Never } else {