chore: replace atty with is-terminal (#156)

This commit is contained in:
sigoden 2023-10-27 14:42:08 +08:00 committed by GitHub
parent 2b8b696b5a
commit 0179bef80d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 31 deletions

25
Cargo.lock generated
View File

@ -33,7 +33,6 @@ dependencies = [
"anyhow", "anyhow",
"arboard", "arboard",
"async-trait", "async-trait",
"atty",
"base64", "base64",
"bincode", "bincode",
"bstr", "bstr",
@ -166,17 +165,6 @@ dependencies = [
"syn 2.0.38", "syn 2.0.38",
] ]
[[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]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.1.0" version = "1.1.0"
@ -749,15 +737,6 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.3" version = "0.3.3"
@ -917,7 +896,7 @@ version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [ dependencies = [
"hermit-abi 0.3.3", "hermit-abi",
"rustix", "rustix",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@ -1112,7 +1091,7 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [ dependencies = [
"hermit-abi 0.3.3", "hermit-abi",
"libc", "libc",
] ]

View File

@ -18,7 +18,7 @@ dirs = "5.0.0"
eventsource-stream = "0.2.3" eventsource-stream = "0.2.3"
futures-util = "0.3.26" futures-util = "0.3.26"
inquire = "0.6.2" inquire = "0.6.2"
is-terminal = "0.4.4" is-terminal = "0.4.9"
reedline = "0.21.0" reedline = "0.21.0"
serde = { version = "1.0.152", features = ["derive"] } serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93" serde_json = "1.0.93"
@ -27,7 +27,6 @@ tokio = { version = "1.26.0", features = ["full"] }
crossbeam = "0.8.2" crossbeam = "0.8.2"
crossterm = "0.26.1" crossterm = "0.26.1"
chrono = "0.4.23" chrono = "0.4.23"
atty = "0.2.14"
unicode-width = "0.1.10" unicode-width = "0.1.10"
bincode = "1.3.3" bincode = "1.3.3"
ctrlc = "3.2.5" ctrlc = "3.2.5"

View File

@ -71,18 +71,18 @@ fn main() -> Result<()> {
} }
let no_stream = cli.no_stream; let no_stream = cli.no_stream;
let client = init_client(config.clone())?; let client = init_client(config.clone())?;
if atty::isnt(atty::Stream::Stdin) { if stdin().is_terminal() {
match text {
Some(text) => start_directive(client.as_ref(), &config, &text, no_stream),
None => start_interactive(config),
}
} else {
let mut input = String::new(); let mut input = String::new();
stdin().read_to_string(&mut input)?; stdin().read_to_string(&mut input)?;
if let Some(text) = text { if let Some(text) = text {
input = format!("{text}\n{input}"); input = format!("{text}\n{input}");
} }
start_directive(client.as_ref(), &config, &input, no_stream) start_directive(client.as_ref(), &config, &input, no_stream)
} else {
match text {
Some(text) => start_directive(client.as_ref(), &config, &text, no_stream),
None => start_interactive(config),
}
} }
} }