From 70163fcdd4a03423fc8216221e1f21120aba257c Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 28 Sep 2023 16:38:00 -0500 Subject: [PATCH] feat(stream): Query the current choice Have a situation in cargo where we use `AutoStream::new` and then need to later check the color choice. Rather than requiring the caller to check both values and `and` them together, let's just report it. Ideally, we could remove those color choice checks but that will take a bit of plumbing work. --- crates/anstream/src/auto.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/anstream/src/auto.rs b/crates/anstream/src/auto.rs index c546638a..2b9d361c 100644 --- a/crates/anstream/src/auto.rs +++ b/crates/anstream/src/auto.rs @@ -131,6 +131,19 @@ where StreamInner::Wincon(_) => true, // its only ever a terminal } } + + /// Prefer [`AutoStream::choice`] + /// + /// This doesn't report what is requested but what is currently active. + #[inline] + pub fn current_choice(&self) -> ColorChoice { + match &self.inner { + StreamInner::PassThrough(_) => ColorChoice::AlwaysAnsi, + StreamInner::Strip(_) => ColorChoice::Never, + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(_) => ColorChoice::Always, + } + } } #[cfg(feature = "auto")]