diff --git a/src/lib.rs b/src/lib.rs index 9792cdb..b9c31fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -466,7 +466,7 @@ pub trait OwoColorize: Sized { #[cfg(feature = "supports-colors")] fn if_supports_color<'a, Out, ApplyFn>( &'a self, - stream: Stream, + stream: impl Into, apply: ApplyFn, ) -> SupportsColorsDisplay<'a, Self, Out, ApplyFn> where @@ -487,7 +487,7 @@ pub use { #[cfg(feature = "supports-colors")] #[doc(no_inline)] -pub use supports_color::Stream; +pub use supports_colors::Stream; pub use colors::{ ansi_colors::AnsiColors, css::dynamic::CssColors, dynamic::Rgb, xterm::dynamic::XtermColors, diff --git a/src/supports_colors.rs b/src/supports_colors.rs index 6280668..686916a 100644 --- a/src/supports_colors.rs +++ b/src/supports_colors.rs @@ -1,5 +1,4 @@ use core::fmt; -use supports_color::Stream; mod private { pub(super) trait Sealed {} @@ -17,8 +16,29 @@ where InVal: ?Sized, ApplyFn: Fn(&'a InVal) -> Out; +/// A possible stream source. +/// +/// This can be used +#[derive(Clone, Copy, Debug)] +pub enum Stream { + /// Standard output. + Stdout, + + /// Standard error. + Stderr, +} + use crate::OVERRIDE; +impl From for Stream { + fn from(stream: supports_color::Stream) -> Self { + match stream { + supports_color::Stream::Stdout => Self::Stdout, + supports_color::Stream::Stderr => Self::Stderr, + } + } +} + macro_rules! impl_fmt_for { ($($trait:path),* $(,)?) => { $( @@ -42,6 +62,10 @@ macro_rules! impl_fmt_for { } fn on_cached(stream: Stream) -> bool { + let stream = match stream { + Stream::Stdout => supports_color::Stream::Stdout, + Stream::Stderr => supports_color::Stream::Stderr, + }; supports_color::on_cached(stream) .map(|level| level.has_basic) .unwrap_or(false)