Skip to content

Commit

Permalink
Remove atty crate and dead code (#667)
Browse files Browse the repository at this point in the history
* We don't show terminal spinners anymore, so let's remove them and their dependencies.
    * If we want to add them back in at some point, we should use lib.rs/spinoff instead as it's still maintained and doesn't use old vulnerable deps.
* Atty is unmaintained and has a RUSTSEC about it. We should use std::io::IsTerminal instead.
  • Loading branch information
adamchalmers authored Jun 3, 2024
1 parent fdaef8d commit 388ce56
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 121 deletions.
95 changes: 3 additions & 92 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ build = "build.rs"
ansi_term = "0.12.1"
anyhow = { version = "1", features = ["backtrace"] }
async-trait = "0.1.80"
atty = "0.2.14"
base64 = "0.22.1"
chrono = { version = "0.4", default-features = false, features = ["serde"] }
clap = { version = "4.5.4", features = ["cargo", "derive", "env", "unicode", "help", "wrap_help"] }
Expand Down Expand Up @@ -52,7 +51,6 @@ slog-term = "2"
tabled = { version = "0.15.0", features = ["ansi"] }
tabwriter = "1.4.0"
termbg = "0.5.0"
terminal-spinners = { git = "https://github.com/adamchalmers/terminal-spinners-rs" }
terminal_size = "0.3.0"
thiserror = "1"
tokio = { version = "1", features = ["full"] }
Expand Down
32 changes: 7 additions & 25 deletions src/iostreams.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::io::IsTerminal;
use std::{collections::HashMap, env, process::Command};

use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -115,7 +116,7 @@ impl IoStreams {
return self.stdin_is_tty;
}

atty::is(atty::Stream::Stdin)
std::io::stdin().is_terminal()
}

pub fn set_stdout_tty(&mut self, is_tty: bool) {
Expand All @@ -128,7 +129,7 @@ impl IoStreams {
return self.stdout_is_tty;
}

atty::is(atty::Stream::Stdout)
std::io::stdout().is_terminal()
}

pub fn set_stderr_tty(&mut self, is_tty: bool) {
Expand All @@ -142,7 +143,7 @@ impl IoStreams {
return self.stderr_is_tty;
}

atty::is(atty::Stream::Stderr)
std::io::stderr().is_terminal()
}

#[allow(dead_code)]
Expand Down Expand Up @@ -220,25 +221,6 @@ impl IoStreams {
self.never_prompt = never_prompt;
}

#[allow(dead_code)]
/// This returns a handle to a spinner. To stop the spinner, call `.stop()` on it.
pub fn start_process_indicator(&mut self) -> Option<terminal_spinners::SpinnerHandle> {
self.start_process_indicator_with_label("")
}

/// This returns a handle to a spinner. To stop the spinner, call `.stop()` on it.
pub fn start_process_indicator_with_label(&mut self, label: &str) -> Option<terminal_spinners::SpinnerHandle> {
if !self.progress_indicator_enabled {
return None;
}

let pi = terminal_spinners::SpinnerBuilder::new()
.spinner(&terminal_spinners::DOTS)
.text(label.to_string());

Some(pi.start())
}

#[allow(dead_code)]
pub fn terminal_width(&self) -> i32 {
if self.terminal_width_override > 0 {
Expand Down Expand Up @@ -348,8 +330,8 @@ impl IoStreams {
}

pub fn system() -> Self {
let stdout_is_tty = atty::is(atty::Stream::Stdout);
let stderr_is_tty = atty::is(atty::Stream::Stderr);
let stdout_is_tty = std::io::stdout().is_terminal();
let stderr_is_tty = std::io::stderr().is_terminal();

#[cfg(windows)]
let mut assume_true_color = false;
Expand Down Expand Up @@ -383,7 +365,7 @@ impl IoStreams {
progress_indicator_enabled: false,

stdin_tty_override: false,
stdin_is_tty: atty::is(atty::Stream::Stdin),
stdin_is_tty: std::io::stdin().is_terminal(),
stdout_tty_override: false,
stdout_is_tty,
stderr_tty_override: false,
Expand Down
4 changes: 2 additions & 2 deletions src/update.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(target_family = "unix")]
use std::os::unix::fs::PermissionsExt;
use std::{fs, io::Write};
use std::{fs, io::IsTerminal, io::Write};

use anyhow::{anyhow, Context, Result};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -69,7 +69,7 @@ fn should_check_for_update() -> bool {
return false;
}

!is_ci() && atty::is(atty::Stream::Stdout) && atty::is(atty::Stream::Stderr)
!is_ci() && std::io::stdout().is_terminal() && std::io::stderr().is_terminal()
}

/// If we are running in a CI environment.
Expand Down

0 comments on commit 388ce56

Please sign in to comment.