Skip to content

Commit

Permalink
cli: switch from atty crate to is-terminal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinvonz committed Nov 23, 2022
1 parent 94815a7 commit 84aa1a4
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 9 deletions.
78 changes: 75 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -34,7 +34,6 @@ harness = false
members = ["lib"]

[dependencies]
atty = "0.2.14"
chrono = { version = "0.4.23", default-features = false, features = ["std", "clock"] }
clap = { version = "4.0.26", features = ["derive", "deprecated"] }
clap_complete = "4.0.5"
Expand All @@ -44,6 +43,7 @@ crossterm = { version = "0.25", default-features = false }
dirs = "4.0.0"
git2 = "0.15.0"
hex = "0.4.3"
is-terminal = "0.4.0"
itertools = "0.10.5"
jujutsu-lib = { version = "=0.5.1", path = "lib"}
once_cell = "1.15.0"
Expand Down
10 changes: 5 additions & 5 deletions src/ui.rs
Expand Up @@ -17,7 +17,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{fmt, io};

use atty::Stream;
use is_terminal::IsTerminal;
use jujutsu_lib::settings::UserSettings;

use crate::formatter::{Formatter, FormatterFactory};
Expand Down Expand Up @@ -80,7 +80,7 @@ fn use_color(choice: ColorChoice) -> bool {
match choice {
ColorChoice::Always => true,
ColorChoice::Never => false,
ColorChoice::Auto => atty::is(Stream::Stdout),
ColorChoice::Auto => io::stdout().is_terminal(),
}
}

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

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

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

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

0 comments on commit 84aa1a4

Please sign in to comment.