Skip to content

Commit

Permalink
Reintroduce owo_colors::Stream to reduce version dependency on suppor…
Browse files Browse the repository at this point in the history
…ts_color
  • Loading branch information
jam1garner committed Oct 12, 2023
1 parent 7dad7ea commit 50217bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Stream>,
apply: ApplyFn,
) -> SupportsColorsDisplay<'a, Self, Out, ApplyFn>
where
Expand All @@ -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,
Expand Down
26 changes: 25 additions & 1 deletion src/supports_colors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::fmt;
use supports_color::Stream;

mod private {
pub(super) trait Sealed {}
Expand All @@ -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<supports_color::Stream> 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),* $(,)?) => {
$(
Expand All @@ -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)
Expand Down

0 comments on commit 50217bc

Please sign in to comment.