Skip to content

Commit

Permalink
feat(tty): Switch from atty to is-terminal (#4)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the exported `Stream` enum is no longer an `atty` type, and this crate no longer accepts `atty` types as input.
  • Loading branch information
Porges committed Mar 14, 2023
1 parent 20e4ff5 commit 86bf758
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
### Features

* **api:** initial commit ([0b57e63a](https://github.com/zkat/supports-unicode/commit/0b57e63a443d4aab57ecf24868394e0d06984465))

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ readme = "README.md"
edition = "2018"

[dependencies]
atty = "0.2.14"
is-terminal = "0.4.0"
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#![doc = include_str!("../README.md")]

pub use atty::Stream;
/// possible stream sources
#[derive(Clone, Copy, Debug)]
pub enum Stream {
Stdout,
Stderr,
}

fn is_a_tty(stream: Stream) -> bool {
use is_terminal::*;
match stream {
Stream::Stdout => std::io::stdout().is_terminal(),
Stream::Stderr => std::io::stderr().is_terminal(),
}
}

pub fn on(stream: Stream) -> bool {
if !atty::is(stream) {
if !is_a_tty(stream) {
// If we're just piping out, it's fine to spit out unicode! :)
true
} else if std::env::consts::OS == "windows" {
Expand Down

0 comments on commit 86bf758

Please sign in to comment.