diff --git a/Cargo.lock b/Cargo.lock index 01275828..cd179b7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,17 +110,6 @@ dependencies = [ "syn 2.0.37", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -771,15 +760,6 @@ dependencies = [ "hashbrown 0.14.1", ] -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.3" @@ -994,6 +974,17 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys 0.48.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1285,7 +1276,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi", "libc", ] @@ -1445,7 +1436,6 @@ dependencies = [ "RustyXML", "anyhow", "async-trait", - "atty", "base64", "bindgen", "bytes", @@ -1467,6 +1457,7 @@ dependencies = [ "hyper", "indicatif", "int-enum", + "is-terminal", "itertools", "json", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 6946be94..4484cdea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] anyhow = { version = "1.0", optional = true } async-trait = { version = "0.1", optional = true } -atty = "0.2" base64 = { version = "0.21", optional = true } bytes = { version = "1.4", optional = true } c_fixed_string = { version = "0.2", optional = true } @@ -28,6 +27,7 @@ http-content-range = "0.1" hyper = { version="0.14", features = ["server"], optional = true } indicatif = "0.17.3" int-enum = "0.5" +is-terminal = "0.4" itertools = "0.10" json = "0.12" lazy_static = "1.4" diff --git a/src/opt/use_progress_bar.rs b/src/opt/use_progress_bar.rs index fe98febc..6bf178e8 100644 --- a/src/opt/use_progress_bar.rs +++ b/src/opt/use_progress_bar.rs @@ -1,10 +1,29 @@ use crate::ext::use_or_not::ToBool; use crate::ext::use_or_not::UseOrNot; +use is_terminal::IsTerminal; + +#[derive(Clone, Copy, Debug)] +#[allow(dead_code)] +pub enum StreamType { + Stdout, + Stderr, + Stdin, +} + +impl StreamType { + pub fn is_terminal(&self) -> bool { + match self { + Self::Stdout => std::io::stdout().is_terminal(), + Self::Stderr => std::io::stderr().is_terminal(), + Self::Stdin => std::io::stdin().is_terminal(), + } + } +} #[derive(Clone, Copy, Debug)] pub struct UseProgressBar { v: UseOrNot, - stream: atty::Stream, + stream: StreamType, } impl AsRef for UseProgressBar { @@ -23,7 +42,7 @@ impl Default for UseProgressBar { fn default() -> Self { Self { v: UseOrNot::Auto, - stream: atty::Stream::Stdout, + stream: StreamType::Stdout, } } } @@ -32,16 +51,7 @@ impl From for UseProgressBar { fn from(v: bool) -> Self { Self { v: UseOrNot::from(v), - stream: atty::Stream::Stdout, - } - } -} - -impl From for UseProgressBar { - fn from(stream: atty::Stream) -> Self { - Self { - v: UseOrNot::Auto, - stream, + stream: StreamType::Stdout, } } } @@ -50,13 +60,13 @@ impl From for UseProgressBar { fn from(v: UseOrNot) -> Self { Self { v, - stream: atty::Stream::Stdout, + stream: StreamType::Stdout, } } } impl ToBool for UseProgressBar { fn detect(&self) -> bool { - atty::is(self.stream) + self.stream.is_terminal() } } diff --git a/src/opthelper.rs b/src/opthelper.rs index 6bce67a8..0d3c0cf5 100644 --- a/src/opthelper.rs +++ b/src/opthelper.rs @@ -19,6 +19,7 @@ use crate::server::cors::CorsEntry; use crate::settings::SettingStore; #[cfg(feature = "ugoira")] use crate::ugoira::X264Profile; +use is_terminal::IsTerminal; #[cfg(feature = "server")] use std::net::IpAddr; #[cfg(feature = "server")] @@ -462,7 +463,7 @@ impl OptHelper { if self._use_progress_bar.get_ref().is_some() { return self._use_progress_bar.get_ref().as_ref().unwrap().to_bool(); } - atty::is(atty::Stream::Stdout) + std::io::stdout().is_terminal() } /// Return progress bar's template