Skip to content

Commit 84aa1a4

Browse files
committed
cli: switch from atty crate to is-terminal
The `atty` crate seems unmaintained. There's https://rustsec.org/advisories/RUSTSEC-2021-0145 filed against it, which `cargo-deny` complains about. A fix for that has been open for well over a year without being fixed (softprops/atty#51). The `is-terminal` crate is a fork of `atty` with that fixed, plus some other changes.
1 parent 94815a7 commit 84aa1a4

File tree

3 files changed

+81
-9
lines changed

3 files changed

+81
-9
lines changed

Cargo.lock

Lines changed: 75 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ harness = false
3434
members = ["lib"]
3535

3636
[dependencies]
37-
atty = "0.2.14"
3837
chrono = { version = "0.4.23", default-features = false, features = ["std", "clock"] }
3938
clap = { version = "4.0.26", features = ["derive", "deprecated"] }
4039
clap_complete = "4.0.5"
@@ -44,6 +43,7 @@ crossterm = { version = "0.25", default-features = false }
4443
dirs = "4.0.0"
4544
git2 = "0.15.0"
4645
hex = "0.4.3"
46+
is-terminal = "0.4.0"
4747
itertools = "0.10.5"
4848
jujutsu-lib = { version = "=0.5.1", path = "lib"}
4949
once_cell = "1.15.0"

src/ui.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::path::{Path, PathBuf};
1717
use std::str::FromStr;
1818
use std::{fmt, io};
1919

20-
use atty::Stream;
20+
use is_terminal::IsTerminal;
2121
use jujutsu_lib::settings::UserSettings;
2222

2323
use crate::formatter::{Formatter, FormatterFactory};
@@ -80,7 +80,7 @@ fn use_color(choice: ColorChoice) -> bool {
8080
match choice {
8181
ColorChoice::Always => true,
8282
ColorChoice::Never => false,
83-
ColorChoice::Auto => atty::is(Stream::Stdout),
83+
ColorChoice::Auto => io::stdout().is_terminal(),
8484
}
8585
}
8686

@@ -154,7 +154,7 @@ impl Ui {
154154
/// Whether continuous feedback should be displayed for long-running
155155
/// operations
156156
pub fn use_progress_indicator(&self) -> bool {
157-
self.settings().use_progress_indicator() && atty::is(Stream::Stdout)
157+
self.settings().use_progress_indicator() && io::stdout().is_terminal()
158158
}
159159

160160
pub fn write(&mut self, text: &str) -> io::Result<()> {
@@ -208,7 +208,7 @@ impl Ui {
208208
}
209209

210210
pub fn prompt(&mut self, prompt: &str) -> io::Result<String> {
211-
if !atty::is(Stream::Stdout) {
211+
if !io::stdout().is_terminal() {
212212
return Err(io::Error::new(
213213
io::ErrorKind::Unsupported,
214214
"Cannot prompt for input since the output is not connected to a terminal",
@@ -222,7 +222,7 @@ impl Ui {
222222
}
223223

224224
pub fn prompt_password(&mut self, prompt: &str) -> io::Result<String> {
225-
if !atty::is(Stream::Stdout) {
225+
if !io::stdout().is_terminal() {
226226
return Err(io::Error::new(
227227
io::ErrorKind::Unsupported,
228228
"Cannot prompt for input since the output is not connected to a terminal",

0 commit comments

Comments
 (0)