From 57cc0d843567eef566540074b391f8212d859871 Mon Sep 17 00:00:00 2001 From: Constantin Nickel Date: Wed, 5 Apr 2023 19:26:52 +0200 Subject: [PATCH] Use the `is-terminal` crate instead of `atty` The crate is already used by `clap` and a similar trait is about to be stabilized in `std`. --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- src/bin/bat/app.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b679ca3b..82c255f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,7 +69,6 @@ version = "0.23.0" dependencies = [ "ansi_colours", "assert_cmd", - "atty", "bincode", "bugreport", "bytesize", @@ -84,6 +83,7 @@ dependencies = [ "git2", "globset", "grep-cli", + "is-terminal", "nix", "nu-ansi-term", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 44460e04..c8a3696c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ application = [ # Mainly for developers that want to iterate quickly # Be aware that the included features might change in the future minimal-application = [ - "atty", + "is-terminal", "clap", "dirs", "paging", @@ -41,7 +41,7 @@ regex-onig = ["syntect/regex-onig"] # Use the "oniguruma" regex engine regex-fancy = ["syntect/regex-fancy"] # Use the rust-only "fancy-regex" engine [dependencies] -atty = { version = "0.2.14", optional = true } +is-terminal = { version = "0.4.4", optional = true } nu-ansi-term = "0.47.0" ansi_colours = "^1.2" bincode = "1.0" diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 0dbb91c2..f7f4c4af 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use std::env; use std::path::{Path, PathBuf}; -use atty::{self, Stream}; +use is_terminal::IsTerminal; use crate::{ clap_app, @@ -40,7 +40,7 @@ impl App { #[cfg(windows)] let _ = nu_ansi_term::enable_ansi_support(); - let interactive_output = atty::is(Stream::Stdout); + let interactive_output = std::io::stdout().is_terminal(); Ok(App { matches: Self::matches(interactive_output)?, @@ -104,7 +104,7 @@ impl App { // If we are reading from stdin, only enable paging if we write to an // interactive terminal and if we do not *read* from an interactive // terminal. - if self.interactive_output && !atty::is(Stream::Stdin) { + if self.interactive_output && std::io::stdin().is_terminal() { PagingMode::QuitIfOneScreen } else { PagingMode::Never