Use is_terminal from stdlib instead of atty.

This commit is contained in:
jcamiel 2023-07-03 15:49:38 +02:00 committed by hurl-bot
parent a57d585da0
commit 9775ec5ce6
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
8 changed files with 20 additions and 45 deletions

26
Cargo.lock generated
View File

@ -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",
]

View File

@ -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"] }

View File

@ -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<Option<String>, 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<Vec<String>, 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<String> {

View File

@ -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<Options, OptionsError> {
// 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));
}

View File

@ -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(),
})

View File

@ -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"

View File

@ -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<Vec<String>, OptionsError
}
}
}
if files.is_empty() && !atty::is(Stream::Stdin) {
if files.is_empty() && !io::stdin().is_terminal() {
files.push("-".to_string());
}
Ok(files)

View File

@ -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<Options, OptionsError> {
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));
}