Skip to content

Commit

Permalink
Switch from atty to is-terminal.
Browse files Browse the repository at this point in the history
Use the is-terminal crate for testing whether file handles are
terminals. Unlike atty, is-terminal operates on handles, so Wasmtime's
code can avoid all the `cfg`s.
  • Loading branch information
sunfishcode committed Jan 22, 2022
1 parent a0aaf9f commit 7cb5f06
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion crates/wasi-common/cap-std-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ fs-set-times = "0.14.1"
system-interface = { version = "0.17.0", features = ["cap_std_impls"] }
tracing = "0.1.19"
io-lifetimes = { version = "0.4.4", default-features = false }
is-terminal = "0.0.0"

[target.'cfg(unix)'.dependencies]
rustix = "0.31.0"

[target.'cfg(windows)'.dependencies]
winapi = "0.3"
lazy_static = "1.4"
atty = "0.2.14"

[dev-dependencies]
tempfile = "3.1.0"
10 changes: 2 additions & 8 deletions crates/wasi-common/cap-std-sync/src/file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cap_fs_ext::MetadataExt;
use fs_set_times::{SetTimes, SystemTimeSpec};
use is_terminal::IsTerminal;
use std::any::Any;
use std::convert::TryInto;
use std::io;
Expand Down Expand Up @@ -122,14 +123,7 @@ impl WasiFile for File {
Ok(self.0.num_ready_bytes()?)
}
fn isatty(&self) -> bool {
#[cfg(unix)]
{
rustix::io::isatty(&self.0)
}
#[cfg(windows)]
{
false
}
self.0.is_terminal()
}
async fn readable(&self) -> Result<(), Error> {
Err(Error::badf())
Expand Down
19 changes: 3 additions & 16 deletions crates/wasi-common/cap-std-sync/src/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::file::convert_systimespec;
use fs_set_times::SetTimes;
use io_lifetimes::AsFilelike;
use is_terminal::IsTerminal;
use std::any::Any;
use std::convert::TryInto;
use std::fs::File;
Expand Down Expand Up @@ -109,14 +110,7 @@ impl WasiFile for Stdin {
Ok(self.0.num_ready_bytes()?)
}
fn isatty(&self) -> bool {
#[cfg(unix)]
{
rustix::io::isatty(&self.0)
}
#[cfg(not(unix))]
{
atty::is(atty::Stream::Stdin)
}
self.0.is_terminal()
}
async fn readable(&self) -> Result<(), Error> {
Err(Error::badf())
Expand Down Expand Up @@ -229,14 +223,7 @@ macro_rules! wasi_file_write_impl {
Ok(0)
}
fn isatty(&self) -> bool {
#[cfg(unix)]
{
rustix::io::isatty(&self.0)
}
#[cfg(not(unix))]
{
atty::is(atty::Stream::$ident)
}
self.0.is_terminal()
}
async fn readable(&self) -> Result<(), Error> {
Err(Error::badf())
Expand Down

0 comments on commit 7cb5f06

Please sign in to comment.