Skip to content

Commit

Permalink
Remove atty in favor of is-terminal
Browse files Browse the repository at this point in the history
The std version of it is only usable in v1.70 unfortunately.
  • Loading branch information
Byron committed Aug 22, 2023
1 parent 3ad8226 commit 2bfe9ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ render-tui = ["tui",
render-line = ["crosstermion/color", "humantime", "unicode-width"]
render-line-crossterm = ["crosstermion/crossterm"]
render-line-termion = ["crosstermion/termion"]
render-line-autoconfigure = ["atty"]
render-line-autoconfigure = ["is-terminal"]

local-time = ["time"]

Expand Down Expand Up @@ -88,7 +88,7 @@ time = { version = "0.3.2", optional = true, features = ["std", "local-offset",
# line renderer
ctrlc = { version = "3.1.4", optional = true, default-features = false, features = ['termination'] }
signal-hook = { version = "0.3.9", optional = true, default-features = false }
atty = { version = "0.2.14", optional = true }
is-terminal = { version = "0.4.9", optional = true }

# units
bytesize = { version = "1.0.1", optional = true }
Expand All @@ -105,7 +105,7 @@ criterion = { version = "0.5.1", default-features = false }
futures-util = { version = "0.3.4", default-features = false }
argh = "0.1.3"
futures = "0.3.5"
atty = "0.2.14"
is-terminal = "0.4.9"
blocking = "1.0.0"
once_cell = "1.4.0"
async-executor = "1.1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/shared/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn launch_ambient_gui(
}
.boxed(),
"tui" => {
if atty::isnt(atty::Stream::Stdout) {
if !is_terminal::is_terminal(std::io::stdout()) {
eprintln!("Need a terminal on stdout to draw progress TUI");
futures_lite::future::ready(()).boxed()
} else {
Expand Down
15 changes: 4 additions & 11 deletions src/render/line/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ pub enum StreamKind {
Stderr,
}

#[cfg(feature = "render-line-autoconfigure")]
impl From<StreamKind> for atty::Stream {
fn from(s: StreamKind) -> Self {
match s {
StreamKind::Stdout => atty::Stream::Stdout,
StreamKind::Stderr => atty::Stream::Stderr,
}
}
}

/// Convenience
impl Options {
/// Automatically configure (and overwrite) the following fields based on terminal configuration.
Expand All @@ -94,7 +84,10 @@ impl Options {
/// * hide-cursor (based on presence of 'signal-hook' feature.
#[cfg(feature = "render-line-autoconfigure")]
pub fn auto_configure(mut self, output: StreamKind) -> Self {
self.output_is_terminal = atty::is(output.into());
self.output_is_terminal = match output {
StreamKind::Stdout => is_terminal::is_terminal(std::io::stdout()),
StreamKind::Stderr => is_terminal::is_terminal(std::io::stderr()),
};
self.colored = self.output_is_terminal && crosstermion::color::allowed();
self.terminal_dimensions = crosstermion::terminal::size().unwrap_or((80, 20));
#[cfg(feature = "signal-hook")]
Expand Down

0 comments on commit 2bfe9ad

Please sign in to comment.