Skip to content

Commit

Permalink
refactor(stream): Move IsTerminal with RawStream
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 28, 2023
1 parent 1affc29 commit d4ac7b2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
38 changes: 0 additions & 38 deletions crates/anstream/src/is_terminal.rs

This file was deleted.

3 changes: 1 addition & 2 deletions crates/anstream/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ mod buffer;
#[macro_use]
mod macros;
mod auto;
mod is_terminal;
mod stream;
mod strip;
#[cfg(all(windows, feature = "wincon"))]
mod wincon;

pub use auto::AutoStream;
pub use is_terminal::IsTerminal;
pub use stream::IsTerminal;
pub use stream::RawStream;
pub use strip::StripStream;
#[cfg(all(windows, feature = "wincon"))]
Expand Down
41 changes: 39 additions & 2 deletions crates/anstream/src/stream.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::IsTerminal;

/// Required functionality for underlying [`std::io::Write`] for adaptation
#[cfg(not(all(windows, feature = "wincon")))]
pub trait RawStream: std::io::Write + IsTerminal + private::Sealed {}
Expand All @@ -23,6 +21,45 @@ impl RawStream for std::fs::File {}

impl RawStream for crate::Buffer {}

pub trait IsTerminal {
fn is_terminal(&self) -> bool;
}

impl IsTerminal for std::io::Stdout {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
}
}

impl IsTerminal for std::io::StdoutLock<'static> {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
}
}

impl IsTerminal for std::io::Stderr {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
}
}

impl IsTerminal for std::io::StderrLock<'static> {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
}
}

impl IsTerminal for std::fs::File {
#[inline]
fn is_terminal(&self) -> bool {
std::io::IsTerminal::is_terminal(self)
}
}

mod private {
pub trait Sealed {}

Expand Down

0 comments on commit d4ac7b2

Please sign in to comment.