Skip to content

Commit

Permalink
Replace usage of the atty crate with std::io::IsTerminal trait (#…
Browse files Browse the repository at this point in the history
…1465)

Rust 1.70 stabilized the `IsTerminal` trait and the newest version of
`grep-cli` crate depending on it, makes it possible to remove the
unmaintained `atty` crate from the build.

```
Crate:     atty
Version:   0.2.14
Warning:   unsound
Title:     Potential unaligned read
Date:      2021-07-04
ID:        RUSTSEC-2021-0145
URL:       https://rustsec.org/advisories/RUSTSEC-2021-0145
```
  • Loading branch information
nickelc authored Jul 8, 2023
1 parent ff5fd06 commit 915662f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 43 deletions.
37 changes: 7 additions & 30 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ chrono-humanize = "0.2.2"
ansi_colours = "1.2.1"
ansi_term = "0.12.1"
anyhow = "1.0.70"
atty = "0.2.14"
bitflags = "2.2.1"
box_drawing = "0.1.2"
bytelines = "=2.2.2" # Pin version until its tokio and futures dependencies are optional.
clap = { version = "4.1.11", features = ["derive", "help", "usage", "error-context", "wrap_help"] }
console = "0.15.0"
ctrlc = "3.2.5"
dirs = "5.0.1"
grep-cli = "0.1.7"
grep-cli = "0.1.8"
itertools = "0.10.5"
lazy_static = "1.4"
palette = "0.7.2"
Expand Down
5 changes: 2 additions & 3 deletions src/delta.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::io::BufRead;
use std::io::Write;
use std::io::{self, BufRead, IsTerminal, Write};

use bytelines::ByteLines;

Expand Down Expand Up @@ -260,7 +259,7 @@ impl<'a> StateMachine<'a> {
/// If output is going to a tty, emit hyperlinks if requested.
// Although raw output should basically be emitted unaltered, we do this.
pub fn format_raw_line<'a>(line: &'a str, config: &Config) -> Cow<'a, str> {
if config.hyperlinks && atty::is(atty::Stream::Stdout) {
if config.hyperlinks && io::stdout().is_terminal() {
features::hyperlinks::format_commit_line_with_osc8_commit_hyperlink(line, config)
} else {
Cow::from(line)
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod subcommands;

mod tests;

use std::io::{self, ErrorKind};
use std::io::{self, ErrorKind, IsTerminal};
use std::process;

use bytelines::ByteLinesReader;
Expand Down Expand Up @@ -130,7 +130,7 @@ fn run_app() -> std::io::Result<i32> {
return Ok(exit_code);
}

if atty::is(atty::Stream::Stdin) {
if io::stdin().is_terminal() {
eprintln!(
"\
The main way to use delta is to configure it as the pager for git: \
Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/list_syntax_themes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::{self, Write};
use std::io::{self, IsTerminal, Write};

use itertools::Itertools;

Expand All @@ -8,7 +8,7 @@ use crate::{options::theme::is_light_syntax_theme, utils};
pub fn list_syntax_themes() -> std::io::Result<()> {
let stdout = io::stdout();
let mut stdout = stdout.lock();
if atty::is(atty::Stream::Stdout) {
if stdout.is_terminal() {
_list_syntax_themes_for_humans(&mut stdout)
} else {
_list_syntax_themes_for_machines(&mut stdout)
Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/show_syntax_themes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::options::theme::is_light_syntax_theme;
use crate::utils;
use crate::utils::bat::output::{OutputType, PagingMode};
use clap::Parser;
use std::io::{self, ErrorKind, Read, Write};
use std::io::{self, ErrorKind, IsTerminal, Read, Write};

#[cfg(not(tarpaulin_include))]
pub fn show_syntax_themes() -> std::io::Result<()> {
Expand All @@ -21,7 +21,7 @@ pub fn show_syntax_themes() -> std::io::Result<()> {
.unwrap();
let mut writer = output_type.handle().unwrap();

let stdin_data = if !atty::is(atty::Stream::Stdin) {
let stdin_data = if !io::stdin().is_terminal() {
let mut buf = Vec::new();
io::stdin().lock().read_to_end(&mut buf)?;
if !buf.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions src/subcommands/show_themes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::{self, ErrorKind, Read};
use std::io::{self, ErrorKind, IsTerminal, Read};

use crate::cli;
use crate::config;
Expand All @@ -17,7 +17,7 @@ pub fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> st

let mut input = DIFF.to_vec();

if !atty::is(atty::Stream::Stdin) {
if !io::stdin().is_terminal() {
let mut buf = Vec::new();
io::stdin().lock().read_to_end(&mut buf)?;
if !buf.is_empty() {
Expand Down

0 comments on commit 915662f

Please sign in to comment.