Skip to content

Commit 11a6608

Browse files
authored
Remove usage of is-terminal and atty crates (bytecodealliance#7104)
* 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
1 parent 90e4daf commit 11a6608

File tree

8 files changed

+16
-19
lines changed

8 files changed

+16
-19
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/environ/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ wasmprinter = { workspace = true, optional = true }
2828
wasmtime-component-util = { workspace = true, optional = true }
2929

3030
[dev-dependencies]
31-
atty = "0.2.14"
3231
clap = { workspace = true }
3332
env_logger = { workspace = true }
3433
wat = { workspace = true }

crates/environ/examples/factc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::{bail, Context, Result};
22
use clap::Parser;
3-
use std::io::Write;
3+
use std::io::{IsTerminal, Write};
44
use std::path::PathBuf;
55
use wasmparser::{Validator, WasmFeatures};
66
use wasmtime_environ::component::*;
@@ -179,7 +179,7 @@ impl Factc {
179179
wasmprinter::print_bytes(&wasm)
180180
.context("failed to convert binary wasm to text")?
181181
.into_bytes()
182-
} else if self.output.is_none() && atty::is(atty::Stream::Stdout) {
182+
} else if self.output.is_none() && std::io::stdout().is_terminal() {
183183
bail!("cannot print binary wasm output to a terminal unless `-t` flag is passed")
184184
} else {
185185
wasm.clone()

crates/test-programs/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ http = { version = "0.2.9" }
2020
http-body = "1.0.0-rc.2"
2121
http-body-util = "0.1.0-rc.2"
2222
hyper = { version = "1.0.0-rc.3", features = ["full"] }
23-
is-terminal = { workspace = true }
2423
tokio = { workspace = true, features = ["net", "rt-multi-thread", "macros"] }
2524
tracing = { workspace = true }
2625

crates/test-programs/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
///! This crate exists to build crates for wasm32-wasi in build.rs, and execute
22
///! these wasm programs in harnesses defined under tests/.
3+
use std::io::IsTerminal;
34

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

4243
pub fn stdio_is_terminal() -> bool {
43-
use is_terminal::is_terminal;
44-
is_terminal(&std::io::stdin())
45-
&& is_terminal(&std::io::stdout())
46-
&& is_terminal(&std::io::stderr())
44+
std::io::stdin().is_terminal()
45+
&& std::io::stdout().is_terminal()
46+
&& std::io::stderr().is_terminal()
4747
}

crates/wasi-common/cap-std-sync/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ fs-set-times = { workspace = true }
2323
system-interface = { workspace = true, features = ["cap_std_impls"] }
2424
tracing = { workspace = true }
2525
io-lifetimes = { workspace = true }
26-
is-terminal = { workspace = true }
2726

2827
[target.'cfg(unix)'.dependencies]
2928
rustix = { workspace = true, features = ["fs", "event"] }

crates/wasi-common/cap-std-sync/src/file.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use cap_fs_ext::MetadataExt;
22
use fs_set_times::{SetTimes, SystemTimeSpec};
33
use io_lifetimes::AsFilelike;
4-
use is_terminal::IsTerminal;
54
use std::any::Any;
65
use std::convert::TryInto;
7-
use std::io;
6+
use std::io::{self, IsTerminal};
87
use system_interface::{
98
fs::{FileIoExt, GetSetFdFlags},
109
io::{IoExt, ReadReady},
@@ -128,7 +127,10 @@ impl WasiFile for File {
128127
Ok(self.0.num_ready_bytes()?)
129128
}
130129
fn isatty(&self) -> bool {
131-
self.0.is_terminal()
130+
#[cfg(unix)]
131+
return self.0.as_fd().is_terminal();
132+
#[cfg(windows)]
133+
return self.0.as_handle().is_terminal();
132134
}
133135
}
134136

crates/wasi-common/cap-std-sync/src/stdio.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use crate::file::convert_systimespec;
22
use fs_set_times::SetTimes;
3-
use is_terminal::IsTerminal;
43
use std::any::Any;
54
use std::convert::TryInto;
6-
use std::io;
7-
use std::io::{Read, Write};
5+
use std::io::{self, IsTerminal, Read, Write};
86
use system_interface::io::ReadReady;
97

108
#[cfg(windows)]
@@ -77,7 +75,10 @@ impl WasiFile for Stdin {
7775
Ok(self.0.num_ready_bytes()?)
7876
}
7977
fn isatty(&self) -> bool {
80-
self.0.is_terminal()
78+
#[cfg(unix)]
79+
return self.0.as_fd().is_terminal();
80+
#[cfg(windows)]
81+
return self.0.as_handle().is_terminal();
8182
}
8283
}
8384
#[cfg(windows)]

0 commit comments

Comments
 (0)