Skip to content

Commit

Permalink
Merge pull request #2859 from fermyon/remove-atty
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev authored Sep 24, 2024
2 parents a478da4 + 4bc0bf6 commit bb0065d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/terminal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ authors = { workspace = true }
edition = { workspace = true }

[dependencies]
atty = "0.2"
termcolor = "1"
10 changes: 5 additions & 5 deletions crates/terminal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This library is used by Spin to print out messages in an appropriate format
//! that is easy for users to read. This is not meant as a general purpose library.
use std::sync::OnceLock;
use std::{io::IsTerminal, sync::OnceLock};
use termcolor::{ColorSpec, StandardStream, StandardStreamLock, WriteColor};

static COLOR_OUT: OnceLock<StandardStream> = OnceLock::new();
Expand All @@ -16,14 +16,14 @@ impl ColorText {
/// Create a `ColorText` tied to stdout
pub fn stdout(spec: ColorSpec) -> ColorText {
let stream =
COLOR_OUT.get_or_init(|| StandardStream::stdout(color_choice(atty::Stream::Stdout)));
COLOR_OUT.get_or_init(|| StandardStream::stdout(color_choice(std::io::stdout())));
set_color(stream, spec)
}

/// Create a `ColorText` tied to stderr
pub fn stderr(spec: ColorSpec) -> ColorText {
let stream =
COLOR_ERR.get_or_init(|| StandardStream::stderr(color_choice(atty::Stream::Stderr)));
COLOR_ERR.get_or_init(|| StandardStream::stderr(color_choice(std::io::stderr())));
set_color(stream, spec)
}
}
Expand Down Expand Up @@ -64,8 +64,8 @@ fn set_color(stream: &'static StandardStream, spec: ColorSpec) -> ColorText {
ColorText(lock)
}

fn color_choice(stream: atty::Stream) -> termcolor::ColorChoice {
if atty::is(stream) {
fn color_choice(stream: impl IsTerminal) -> termcolor::ColorChoice {
if stream.is_terminal() {
termcolor::ColorChoice::Auto
} else {
termcolor::ColorChoice::Never
Expand Down

0 comments on commit bb0065d

Please sign in to comment.