Use is-terminal instead of atty.

Following up on #3696, use the new is-terminal crate to test for a tty
rather than having platform-specific logic in Wasmtime. The is-terminal
crate has a platform-independent API which takes a handle.

This also updates the tree to cap-std 0.24 etc., to avoid depending on
multiple versions of io-lifetimes at once, as enforced by the cargo deny
check.
This commit is contained in:
Dan Gohman
2022-01-24 10:56:47 -08:00
parent 491e98233e
commit ffa9fe32aa
14 changed files with 84 additions and 82 deletions

View File

@@ -15,23 +15,23 @@ include = ["src/**/*", "README.md", "LICENSE" ]
wasi-common = { path = "../", version = "=0.33.0" }
async-trait = "0.1"
anyhow = "1.0"
cap-std = "0.22.0"
cap-fs-ext = "0.22.0"
cap-time-ext = "0.22.0"
cap-rand = "0.22.0"
fs-set-times = "0.14.1"
system-interface = { version = "0.17.0", features = ["cap_std_impls"] }
cap-std = "0.24.0"
cap-fs-ext = "0.24.0"
cap-time-ext = "0.24.0"
cap-rand = "0.24.0"
fs-set-times = "0.15.0"
system-interface = { version = "0.20.0", features = ["cap_std_impls"] }
tracing = "0.1.19"
io-lifetimes = { version = "0.4.4", default-features = false }
io-lifetimes = { version = "0.5.0", default-features = false }
is-terminal = "0.1.0"
[target.'cfg(unix)'.dependencies]
rustix = "0.31.0"
rustix = "0.33.0"
[target.'cfg(windows)'.dependencies]
winapi = "0.3"
lazy_static = "1.4"
atty = "0.2.14"
io-extras = "0.12.0"
io-extras = "0.13.0"
[dev-dependencies]
tempfile = "3.1.0"

View File

@@ -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;
@@ -125,14 +126,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())

View File

@@ -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;
@@ -111,14 +112,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())
@@ -242,14 +236,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())