Skip to content

Commit

Permalink
Use built-in is_terminal instead of is_terminal::is_terminal (#9550)
Browse files Browse the repository at this point in the history
# Description
This PR tries to remove ~atty~ is-terminal from the entire code base,
since ~[atty is
unmaintained](https://rustsec.org/advisories/RUSTSEC-2021-0145) and~
[`is_terminal` has been
stabilized](https://blog.rust-lang.org/2023/06/01/Rust-1.70.0.html#isterminal)
in rust 1.70.0.

cc @fdncred 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
  • Loading branch information
nibon7 committed Aug 25, 2023
1 parent 27dcc3e commit ad12018
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 13 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ nix = { version = "0.26", default-features = false, features = [
"fs",
"term",
] }
is-terminal = "0.4.8"

[dev-dependencies]
nu-test-support = { path = "./crates/nu-test-support", version = "0.84.1" }
Expand Down
1 change: 0 additions & 1 deletion crates/nu-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ 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.10", features = ["fancy-no-backtrace"] }
once_cell = "1.18"
Expand Down
3 changes: 1 addition & 2 deletions crates/nu-cli/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 All @@ -26,7 +25,7 @@ use reedline::{
SqliteBackedHistory, Vi,
};
use std::{
io::{self, Write},
io::{self, IsTerminal, Write},
path::Path,
sync::atomic::Ordering,
time::Instant,
Expand Down
1 change: 0 additions & 1 deletion crates/nu-command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fs_extra = "1.3"
htmlescape = "0.3"
indexmap = "2.0"
indicatif = "0.17"
is-terminal = "0.4.8"
itertools = "0.10"
log = "0.4"
lscolors = { version = "0.15", default-features = false, features = ["nu-ansi-term"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-command/src/viewers/table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use is_terminal::IsTerminal;
use lscolors::{LsColors, Style};
use nu_color_config::color_from_hex;
use nu_color_config::{StyleComputer, TextStyle};
Expand All @@ -15,6 +14,7 @@ use nu_table::{
TableOutput,
};
use nu_utils::get_ls_colors;
use std::io::IsTerminal;
use std::sync::Arc;
use std::time::Instant;
use std::{path::PathBuf, sync::atomic::AtomicBool};
Expand Down
1 change: 0 additions & 1 deletion crates/nu-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ log = "0.4"

[target.'cfg(target_family = "unix")'.dependencies]
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
2 changes: 1 addition & 1 deletion crates/nu-system/src/foreground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ impl Drop for ForegroundChild {
// It's a simpler version of fish shell's external process handling.
#[cfg(unix)]
mod fg_process_setup {
use is_terminal::IsTerminal;
use nix::{
sys::signal,
unistd::{self, Pid},
};
use std::io::IsTerminal;
use std::os::unix::prelude::{CommandExt, RawFd};

// TODO: when raising MSRV past 1.63.0, switch to OwnedFd
Expand Down
2 changes: 1 addition & 1 deletion src/terminal.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[cfg(unix)]
pub(crate) fn acquire_terminal(interactive: bool) {
use is_terminal::IsTerminal;
use nix::{
errno::Errno,
sys::signal::{signal, SigHandler, Signal},
unistd,
};
use std::io::IsTerminal;

if interactive && std::io::stdin().is_terminal() {
// see also: https://www.gnu.org/software/libc/manual/html_node/Initializing-the-Shell.html
Expand Down

0 comments on commit ad12018

Please sign in to comment.