Skip to content

Commit

Permalink
Remove usage of is-terminal and atty crates (#7104)
Browse files Browse the repository at this point in the history
* Remove usage of `is-terminal` and `atty` crates

This functionality is now folded into the standard library itself.

* Fix syntax

* Fix a unix/windows cfg
  • Loading branch information
alexcrichton authored Sep 29, 2023
1 parent 90e4daf commit 11a6608
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 19 deletions.
3 changes: 0 additions & 3 deletions 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/environ/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ wasmprinter = { workspace = true, optional = true }
wasmtime-component-util = { workspace = true, optional = true }

[dev-dependencies]
atty = "0.2.14"
clap = { workspace = true }
env_logger = { workspace = true }
wat = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/environ/examples/factc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Context, Result};
use clap::Parser;
use std::io::Write;
use std::io::{IsTerminal, Write};
use std::path::PathBuf;
use wasmparser::{Validator, WasmFeatures};
use wasmtime_environ::component::*;
Expand Down Expand Up @@ -179,7 +179,7 @@ impl Factc {
wasmprinter::print_bytes(&wasm)
.context("failed to convert binary wasm to text")?
.into_bytes()
} else if self.output.is_none() && atty::is(atty::Stream::Stdout) {
} else if self.output.is_none() && std::io::stdout().is_terminal() {
bail!("cannot print binary wasm output to a terminal unless `-t` flag is passed")
} else {
wasm.clone()
Expand Down
1 change: 0 additions & 1 deletion crates/test-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ http = { version = "0.2.9" }
http-body = "1.0.0-rc.2"
http-body-util = "0.1.0-rc.2"
hyper = { version = "1.0.0-rc.3", features = ["full"] }
is-terminal = { workspace = true }
tokio = { workspace = true, features = ["net", "rt-multi-thread", "macros"] }
tracing = { workspace = true }

Expand Down
8 changes: 4 additions & 4 deletions crates/test-programs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
///! This crate exists to build crates for wasm32-wasi in build.rs, and execute
///! these wasm programs in harnesses defined under tests/.
use std::io::IsTerminal;

#[cfg(all(feature = "test_programs", not(skip_wasi_http_tests)))]
pub mod http_server;
Expand Down Expand Up @@ -40,8 +41,7 @@ pub fn wasi_tests_environment() -> &'static [(&'static str, &'static str)] {
}

pub fn stdio_is_terminal() -> bool {
use is_terminal::is_terminal;
is_terminal(&std::io::stdin())
&& is_terminal(&std::io::stdout())
&& is_terminal(&std::io::stderr())
std::io::stdin().is_terminal()
&& std::io::stdout().is_terminal()
&& std::io::stderr().is_terminal()
}
1 change: 0 additions & 1 deletion crates/wasi-common/cap-std-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fs-set-times = { workspace = true }
system-interface = { workspace = true, features = ["cap_std_impls"] }
tracing = { workspace = true }
io-lifetimes = { workspace = true }
is-terminal = { workspace = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true, features = ["fs", "event"] }
Expand Down
8 changes: 5 additions & 3 deletions crates/wasi-common/cap-std-sync/src/file.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use cap_fs_ext::MetadataExt;
use fs_set_times::{SetTimes, SystemTimeSpec};
use io_lifetimes::AsFilelike;
use is_terminal::IsTerminal;
use std::any::Any;
use std::convert::TryInto;
use std::io;
use std::io::{self, IsTerminal};
use system_interface::{
fs::{FileIoExt, GetSetFdFlags},
io::{IoExt, ReadReady},
Expand Down Expand Up @@ -128,7 +127,10 @@ impl WasiFile for File {
Ok(self.0.num_ready_bytes()?)
}
fn isatty(&self) -> bool {
self.0.is_terminal()
#[cfg(unix)]
return self.0.as_fd().is_terminal();
#[cfg(windows)]
return self.0.as_handle().is_terminal();
}
}

Expand Down
9 changes: 5 additions & 4 deletions crates/wasi-common/cap-std-sync/src/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::file::convert_systimespec;
use fs_set_times::SetTimes;
use is_terminal::IsTerminal;
use std::any::Any;
use std::convert::TryInto;
use std::io;
use std::io::{Read, Write};
use std::io::{self, IsTerminal, Read, Write};
use system_interface::io::ReadReady;

#[cfg(windows)]
Expand Down Expand Up @@ -77,7 +75,10 @@ impl WasiFile for Stdin {
Ok(self.0.num_ready_bytes()?)
}
fn isatty(&self) -> bool {
self.0.is_terminal()
#[cfg(unix)]
return self.0.as_fd().is_terminal();
#[cfg(windows)]
return self.0.as_handle().is_terminal();
}
}
#[cfg(windows)]
Expand Down

0 comments on commit 11a6608

Please sign in to comment.