From 7cb5f060bf6266db5897ec8dd912fea5b3797841 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 21 Jan 2022 18:51:46 -0800 Subject: [PATCH] Switch from atty to is-terminal. 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. --- crates/wasi-common/cap-std-sync/Cargo.toml | 2 +- crates/wasi-common/cap-std-sync/src/file.rs | 10 ++-------- crates/wasi-common/cap-std-sync/src/stdio.rs | 19 +++---------------- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/crates/wasi-common/cap-std-sync/Cargo.toml b/crates/wasi-common/cap-std-sync/Cargo.toml index ac85ee8a7962..dad58828407e 100644 --- a/crates/wasi-common/cap-std-sync/Cargo.toml +++ b/crates/wasi-common/cap-std-sync/Cargo.toml @@ -23,6 +23,7 @@ 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" @@ -30,7 +31,6 @@ 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" diff --git a/crates/wasi-common/cap-std-sync/src/file.rs b/crates/wasi-common/cap-std-sync/src/file.rs index b789c94e2b69..ccfe9750c63d 100644 --- a/crates/wasi-common/cap-std-sync/src/file.rs +++ b/crates/wasi-common/cap-std-sync/src/file.rs @@ -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; @@ -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()) diff --git a/crates/wasi-common/cap-std-sync/src/stdio.rs b/crates/wasi-common/cap-std-sync/src/stdio.rs index db0f5f6ea338..244871c714a6 100644 --- a/crates/wasi-common/cap-std-sync/src/stdio.rs +++ b/crates/wasi-common/cap-std-sync/src/stdio.rs @@ -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; @@ -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()) @@ -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())