Skip to content

Commit

Permalink
Use is-terminal crate for now
Browse files Browse the repository at this point in the history
Until we bump our minimal Rust version to `1.70.0` we can't use
`std::io::IsTerminal`. The crate `is-terminal` (depending on `rustix` or
`windows-sys`) can provide the same.
Get's rid of the dependency on the outdated `atty` crate.
We already transitively depend on it (e.g. through `miette`)

As soon as we reach the new Rust version we can supersede this with
@nibon7's nushell#9550

Co-authored-by: nibon7 <nibon7@163.com>
  • Loading branch information
sholderbach and nibon7 committed Jul 12, 2023
1 parent bd00328 commit 6ffab8a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 50 deletions.
46 changes: 7 additions & 39 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ nix = { version = "0.26", default-features = false, features = [
"fs",
"term",
] }
atty = "0.2"
is-terminal = "0.4.8"

[dev-dependencies]
nu-test-support = { path = "./crates/nu-test-support", version = "0.82.1" }
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ nu-color-config = { path = "../nu-color-config", version = "0.82.1" }
nu-ansi-term = "0.47.0"
reedline = { version = "0.21.0", features = ["bashisms", "sqlite"]}

atty = "0.2"
chrono = { default-features = false, features = ["std"], version = "0.4" }
crossterm = "0.26"
fancy-regex = "0.11"
fuzzy-matcher = "0.3"
is_executable = "1.0"
is-terminal = "0.4.8"
log = "0.4"
miette = { version = "5.9", features = ["fancy-no-backtrace"] }
once_cell = "1.18"
Expand Down
3 changes: 2 additions & 1 deletion crates/nu-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
NuHighlighter, NuValidator, NushellPrompt,
};
use crossterm::cursor::SetCursorStyle;
use is_terminal::IsTerminal;
use log::{trace, warn};
use miette::{ErrReport, IntoDiagnostic, Result};
use nu_cmd_base::util::get_guaranteed_cwd;
Expand Down Expand Up @@ -56,7 +57,7 @@ pub fn evaluate_repl(

// Guard against invocation without a connected terminal.
// reedline / crossterm event polling will fail without a connected tty
if !atty::is(atty::Stream::Stdin) {
if !std::io::stdin().is_terminal() {
return Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"Nushell launched as a REPL, but STDIN is not a TTY; either launch in a valid terminal or provide arguments to invoke a script!",
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ nu-utils = { path = "../nu-utils", version = "0.82.1" }

Inflector = "0.11"
alphanumeric-sort = "1.5"
atty = "0.2"
base64 = "0.21"
byteorder = "1.4"
bytesize = "1.2"
Expand All @@ -52,6 +51,7 @@ htmlescape = "0.3"
indexmap = "2.0"
indicatif = "0.17"
is-root = "0.1"
is-terminal = "0.4.8"
itertools = "0.10"
log = "0.4"
lscolors = { version = "0.14", default-features = false, features = ["nu-ansi-term"] }
Expand Down Expand Up @@ -124,7 +124,7 @@ nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.82.1" }
nu-test-support = { path = "../nu-test-support", version = "0.82.1" }

dirs-next = "2.0"
mockito = "1.1"
mockito = { version = "1.1", default-features = false }
quickcheck = "1.0"
quickcheck_macros = "1.0"
rstest = { version = "0.17", default-features = false }
5 changes: 3 additions & 2 deletions crates/nu-command/src/viewers/table.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use is_terminal::IsTerminal;
use lscolors::{LsColors, Style};
use nu_color_config::color_from_hex;
use nu_color_config::{StyleComputer, TextStyle};
Expand Down Expand Up @@ -848,8 +849,8 @@ enum TableView {

#[allow(clippy::manual_filter)]
fn maybe_strip_color(output: String, config: &Config) -> String {
// the atty is for when people do ls from vim, there should be no coloring there
if !config.use_ansi_coloring || !atty::is(atty::Stream::Stdout) {
// the terminal is for when people do ls from vim, there should be no coloring there
if !config.use_ansi_coloring || !std::io::stdout().is_terminal() {
// Draw the table without ansi colors
nu_utils::strip_ansi_string_likely(output)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ libc = "0.2"
log = "0.4"

[target.'cfg(target_family = "unix")'.dependencies]
atty = "0.2"
nix = { version = "0.26", default-features = false, features = ["fs", "term", "process", "signal"]}
is-terminal = "0.4.8"

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
procfs = "0.15"
Expand Down
5 changes: 3 additions & 2 deletions crates/nu-system/src/foreground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl Drop for ForegroundChild {
// Note: we exclude macos because the techniques below seem to have issues in macos 13 currently.
#[cfg(all(target_family = "unix", not(target_os = "macos")))]
mod fg_process_setup {
use is_terminal::IsTerminal;
use nix::{
sys::signal,
unistd::{self, Pid},
Expand Down Expand Up @@ -138,7 +139,7 @@ mod fg_process_setup {

pub(super) fn set_foreground(process: &std::process::Child, existing_pgrp: u32) {
// called from the parent shell process - do the stdin tty check here
if atty::is(atty::Stream::Stdin) {
if std::io::stdin().is_terminal() {
set_foreground_pid(
Pid::from_raw(process.id() as i32),
existing_pgrp,
Expand All @@ -163,7 +164,7 @@ mod fg_process_setup {

/// Reset the foreground process group to the shell
pub(super) fn reset_foreground_id() {
if atty::is(atty::Stream::Stdin) {
if std::io::stdin().is_terminal() {
if let Err(e) = nix::unistd::tcsetpgrp(nix::libc::STDIN_FILENO, unistd::getpgrp()) {
println!("ERROR: reset foreground id failed, tcsetpgrp result: {e:?}");
}
Expand Down
3 changes: 2 additions & 1 deletion src/terminal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(unix)]
pub(crate) fn acquire_terminal(interactive: bool) {
use is_terminal::IsTerminal;
use nix::sys::signal::{signal, SigHandler, Signal};

if !atty::is(atty::Stream::Stdin) {
if !std::io::stdin().is_terminal() {
return;
}

Expand Down

0 comments on commit 6ffab8a

Please sign in to comment.