From 9775ec5ce6dfc2636a1c85f348f11949420451ff Mon Sep 17 00:00:00 2001 From: jcamiel Date: Mon, 3 Jul 2023 15:49:38 +0200 Subject: [PATCH] Use is_terminal from stdlib instead of atty. --- Cargo.lock | 26 ++------------------- packages/hurl/Cargo.toml | 1 - packages/hurl/src/cli/options/matches.rs | 11 ++++----- packages/hurl/src/cli/options/mod.rs | 6 ++--- packages/hurl/src/output/stdout.rs | 7 +++--- packages/hurlfmt/Cargo.toml | 1 - packages/hurlfmt/src/cli/options/matches.rs | 7 +++--- packages/hurlfmt/src/cli/options/mod.rs | 6 ++--- 8 files changed, 20 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b2751dc9..85cf7b716 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,17 +96,6 @@ dependencies = [ "windows-sys", ] -[[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" @@ -483,15 +472,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -[[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.2" @@ -514,7 +494,6 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "hurl" version = "4.1.0-SNAPSHOT" dependencies = [ - "atty", "base64", "brotli", "cc", @@ -559,7 +538,6 @@ dependencies = [ name = "hurlfmt" version = "4.1.0-SNAPSHOT" dependencies = [ - "atty", "base64", "clap", "colored", @@ -626,7 +604,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "libc", "windows-sys", ] @@ -637,7 +615,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "rustix 0.38.2", "windows-sys", ] diff --git a/packages/hurl/Cargo.toml b/packages/hurl/Cargo.toml index 6702fbbbb..753ab4910 100644 --- a/packages/hurl/Cargo.toml +++ b/packages/hurl/Cargo.toml @@ -18,7 +18,6 @@ name = "hurl" strict = [] [dependencies] -atty = "0.2.14" base64 = "0.21.2" brotli = "3.3.4" chrono = { version = "0.4.26", default-features = false, features = ["clock"] } diff --git a/packages/hurl/src/cli/options/matches.rs b/packages/hurl/src/cli/options/matches.rs index 338802946..fb22b8a1b 100644 --- a/packages/hurl/src/cli/options/matches.rs +++ b/packages/hurl/src/cli/options/matches.rs @@ -19,16 +19,15 @@ use super::variables::{parse as parse_variable, parse_value}; use super::OptionsError; use crate::cli::options::ErrorFormat; use crate::cli::OutputType; -use atty::Stream; use clap::ArgMatches; use hurl::runner::Value; use hurl_core::ast::Retry; use std::collections::HashMap; -use std::env; use std::fs::File; -use std::io::{BufRead, BufReader}; +use std::io::{BufRead, BufReader, IsTerminal}; use std::path::{Path, PathBuf}; use std::time::Duration; +use std::{env, io}; pub fn cacert_file(arg_matches: &ArgMatches) -> Result, OptionsError> { match get_string(arg_matches, "cacert_file") { @@ -88,7 +87,7 @@ pub fn color(arg_matches: &ArgMatches) -> bool { return false; } } - atty::is(Stream::Stdout) + io::stdout().is_terminal() } pub fn compressed(arg_matches: &ArgMatches) -> bool { @@ -184,7 +183,7 @@ pub fn input_files(arg_matches: &ArgMatches) -> Result, OptionsError for filename in glob_files(arg_matches)? { files.push(filename); } - if files.is_empty() && !atty::is(Stream::Stdin) { + if files.is_empty() && !io::stdin().is_terminal() { files.push("-".to_string()); } Ok(files) @@ -237,7 +236,7 @@ pub fn progress_bar(arg_matches: &ArgMatches) -> bool { && !verbose && !interactive(arg_matches) && !is_ci() - && atty::is(Stream::Stderr) + && io::stderr().is_terminal() } pub fn proxy(arg_matches: &ArgMatches) -> Option { diff --git a/packages/hurl/src/cli/options/mod.rs b/packages/hurl/src/cli/options/mod.rs index 98ab9cfa0..2d853dbbc 100644 --- a/packages/hurl/src/cli/options/mod.rs +++ b/packages/hurl/src/cli/options/mod.rs @@ -20,11 +20,11 @@ mod matches; mod variables; use std::collections::HashMap; -use std::env; +use std::io::IsTerminal; use std::path::{Path, PathBuf}; use std::time::Duration; +use std::{env, io}; -use atty::Stream; use clap::ArgMatches; use hurl::libcurl_version_info; use hurl::util::logger::{LoggerOptions, LoggerOptionsBuilder, Verbosity}; @@ -171,7 +171,7 @@ pub fn parse() -> Result { // If we've no file input (either from the standard input or from the command line arguments), // we just print help and exit. - if opts.input_files.is_empty() && atty::is(Stream::Stdin) { + if opts.input_files.is_empty() && io::stdin().is_terminal() { let help = command.render_help().to_string(); return Err(OptionsError::Error(help)); } diff --git a/packages/hurl/src/output/stdout.rs b/packages/hurl/src/output/stdout.rs index 9024c732c..035b43d69 100644 --- a/packages/hurl/src/output/stdout.rs +++ b/packages/hurl/src/output/stdout.rs @@ -19,7 +19,7 @@ use std::io; use std::io::Write; #[cfg(target_family = "windows")] -use atty::Stream; +use std::io::IsTerminal; use crate::output::Error; @@ -34,12 +34,11 @@ pub(crate) fn write_stdout(buf: &[u8]) -> Result<(), Error> { #[cfg(target_family = "windows")] pub(crate) fn write_stdout(buf: &[u8]) -> Result<(), Error> { - if atty::is(Stream::Stdout) { + if io::stdout().is_terminal() { println!("{}", String::from_utf8_lossy(buf)); Ok(()) } else { - let stdout = io::stdout(); - let mut handle = stdout.lock(); + let mut handle = io::stdout().lock(); handle.write_all(buf).map_err(|_| Error { message: "Error writing output".to_string(), }) diff --git a/packages/hurlfmt/Cargo.toml b/packages/hurlfmt/Cargo.toml index 88b02a7cd..859eb4793 100644 --- a/packages/hurlfmt/Cargo.toml +++ b/packages/hurlfmt/Cargo.toml @@ -14,7 +14,6 @@ repository = "https://github.com/Orange-OpenSource/hurl" strict = [] [dependencies] -atty = "0.2.14" base64 = "0.21.2" clap = { version = "4.3.10", features = ["cargo", "wrap_help"] } colored = "2.0.3" diff --git a/packages/hurlfmt/src/cli/options/matches.rs b/packages/hurlfmt/src/cli/options/matches.rs index 843335f41..ab21479c4 100644 --- a/packages/hurlfmt/src/cli/options/matches.rs +++ b/packages/hurlfmt/src/cli/options/matches.rs @@ -17,9 +17,10 @@ */ use super::OptionsError; use crate::cli::options::{InputFormat, OutputFormat}; -use atty::Stream; use clap::parser::ValueSource; use clap::ArgMatches; +use std::io; +use std::io::IsTerminal; use std::path::{Path, PathBuf}; pub fn check(arg_matches: &ArgMatches) -> bool { @@ -32,7 +33,7 @@ pub fn color(arg_matches: &ArgMatches) -> bool { } else if has_flag(arg_matches, "no_color") || has_flag(arg_matches, "in_place") { false } else { - atty::is(Stream::Stdout) + io::stdout().is_terminal() } } @@ -98,7 +99,7 @@ pub fn input_files(arg_matches: &ArgMatches) -> Result, OptionsError } } } - if files.is_empty() && !atty::is(Stream::Stdin) { + if files.is_empty() && !io::stdin().is_terminal() { files.push("-".to_string()); } Ok(files) diff --git a/packages/hurlfmt/src/cli/options/mod.rs b/packages/hurlfmt/src/cli/options/mod.rs index ccd14962b..66fd6f8a3 100644 --- a/packages/hurlfmt/src/cli/options/mod.rs +++ b/packages/hurlfmt/src/cli/options/mod.rs @@ -19,10 +19,10 @@ mod commands; mod matches; -use atty::Stream; use clap::ArgMatches; -use std::env; +use std::io::IsTerminal; use std::path::PathBuf; +use std::{env, io}; #[derive(Clone, Debug, PartialEq, Eq)] pub struct Options { @@ -84,7 +84,7 @@ pub fn parse() -> Result { let arg_matches = command.try_get_matches_from_mut(env::args_os())?; let opts = parse_matches(&arg_matches)?; - if opts.input_files.is_empty() && atty::is(Stream::Stdin) { + if opts.input_files.is_empty() && io::stdin().is_terminal() { let help = command.render_help().to_string(); return Err(OptionsError::Error(help)); }