Skip to content

Commit

Permalink
switch from atty to is-terminal
Browse files Browse the repository at this point in the history
It's the more maintained crate and many do it now.
  • Loading branch information
Byron committed Nov 29, 2022
1 parent 6b9632e commit 7304bc1
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 32 deletions.
111 changes: 89 additions & 22 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ fast = ["git-repository/max-performance"]
## Use `clap` 3.0 to build the prettiest, best documented and most user-friendly CLI at the expense of binary size.
## Provides a terminal user interface for detailed and exhaustive progress.
## Provides a line renderer for leaner progress display, without the need for a full-blown TUI.
pretty-cli = [ "gitoxide-core/serde1", "prodash/progress-tree", "prodash/progress-tree-log", "prodash/local-time", "env_logger/humantime", "env_logger/termcolor", "env_logger/atty" ]
pretty-cli = [ "gitoxide-core/serde1", "prodash/progress-tree", "prodash/progress-tree-log", "prodash/local-time", "env_logger/humantime", "env_logger/color", "env_logger/auto-color" ]

## The `--verbose` flag will be powered by an interactive progress mechanism that doubles as log as well as interactive progress
## that appears after a short duration.
prodash-render-line-crossterm = ["prodash-render-line", "prodash/render-line-crossterm", "prodash/signal-hook", "atty", "crosstermion"]
prodash-render-line-crossterm = ["prodash-render-line", "prodash/render-line-crossterm", "prodash/signal-hook", "is-terminal", "crosstermion"]

#! ### Convenience Features
#! These combine common choices of the above features to represent typical builds
Expand All @@ -54,7 +54,7 @@ lean-async = ["fast", "pretty-cli", "gitoxide-core-tools", "gitoxide-core-async-

## As small as it can possibly be, no threading, no fast sha1, line progress only, rust based zlib implementation.
## no networking, local operations only.
small = ["pretty-cli", "git-features/rustsha1", "git-features/zlib-rust-backend", "prodash-render-line", "atty" ]
small = ["pretty-cli", "git-features/rustsha1", "git-features/zlib-rust-backend", "prodash-render-line", "is-terminal" ]

## Makes the crate execute as fast as possible without pulling in C libraries, while keeping everything else minimal akin to the `small` build.
max-pure = ["pretty-cli", "git-features/rustsha1", "git-features/zlib-rust-backend", "prodash-render-line", "prodash-render-tui", "git-repository/max-performance-safe", "http-client-reqwest", "gitoxide-core-blocking-client", "gitoxide-core-tools", "prodash/render-line-autoconfigure" ]
Expand Down Expand Up @@ -90,8 +90,8 @@ git-repository = { version = "^0.29.0", path = "git-repository", default-feature

clap = { version = "3.2.5", features = ["derive", "cargo"] }
prodash = { version = "21.1", optional = true, default-features = false }
atty = { version = "0.2.14", optional = true, default-features = false }
env_logger = { version = "0.9.0", default-features = false }
is-terminal = { version = "0.4.0", optional = true }
env_logger = { version = "0.10.0", default-features = false }
crosstermion = { version = "0.10.1", optional = true, default-features = false }
futures-lite = { version = "1.12.0", optional = true, default-features = false, features = ["std"] }

Expand Down
1 change: 0 additions & 1 deletion git-repository/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ once_cell = "1.14.0"
signal-hook = { version = "0.3.9", default-features = false }
thiserror = "1.0.26"
clru = "0.5.0"
byte-unit = "4.0"
log = "0.4.14"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
smallvec = "1.9.0"
Expand Down
10 changes: 6 additions & 4 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,11 @@ pub fn main() -> Result<()> {
let input = if let Some(path) = pack_path {
PathOrRead::Path(path)
} else {
if atty::is(atty::Stream::Stdin) {
use is_terminal::IsTerminal;
if std::io::stdin().is_terminal() {
anyhow::bail!(
"Refusing to read from standard input as no path is given, but it's a terminal."
)
"Refusing to read from standard input as no path is given, but it's a terminal."
)
}
PathOrRead::Read(Box::new(stdin()))
};
Expand Down Expand Up @@ -856,7 +857,8 @@ pub fn main() -> Result<()> {
}

fn stdin_or_bail() -> Result<std::io::BufReader<std::io::Stdin>> {
if atty::is(atty::Stream::Stdin) {
use is_terminal::IsTerminal;
if std::io::stdin().is_terminal() {
anyhow::bail!("Refusing to read from standard input while a terminal is connected")
}
Ok(BufReader::new(stdin()))
Expand Down

0 comments on commit 7304bc1

Please sign in to comment.