Skip to content

Commit fa17a31

Browse files
committed
sh: remove unnecessary atty dep
IsTerminal trait was introduced in Rust 1.70
1 parent ccb1199 commit fa17a31

File tree

4 files changed

+10
-31
lines changed

4 files changed

+10
-31
lines changed

Cargo.lock

-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sh/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2021"
77
plib = { path = "../plib" }
88
gettext-rs.workspace = true
99
nix = { version = "0.29", features = ["process", "fs", "resource", "signal", "user", "term"] }
10-
atty = "0.2"
1110

1211
[[bin]]
1312
name = "sh"

sh/src/builtin/read.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ use crate::shell::opened_files::{OpenedFile, OpenedFiles, STDIN_FILENO};
1313
use crate::shell::Shell;
1414
use crate::wordexp::expanded_word::ExpandedWord;
1515
use crate::wordexp::split_fields;
16-
use atty::Stream;
1716
use nix::errno::Errno;
18-
use std::os::fd::{AsRawFd, RawFd};
19-
use std::time::Duration;
17+
use std::{io::stdin, time::Duration};
18+
use std::{
19+
io::IsTerminal,
20+
os::fd::{AsRawFd, RawFd},
21+
};
2022

2123
fn bytes_to_string(bytes: Vec<u8>) -> Result<String, BuiltinError> {
2224
String::from_utf8(bytes.to_vec()).map_err(|_| "read: invalid UTF-8".into())
@@ -140,13 +142,13 @@ fn read_from_stdin(
140142
delimiter: u8,
141143
backslash_escape: bool,
142144
) -> Result<ReadResult, BuiltinError> {
143-
if atty::is(Stream::Stdin) {
145+
if stdin().is_terminal() {
144146
let original_terminal_settings = shell.terminal.reset();
145147
shell.terminal.set_nonblocking();
146148

147149
let result = read_until_from_non_blocking_fd(
148150
shell,
149-
std::io::stdin().as_raw_fd(),
151+
stdin().as_raw_fd(),
150152
delimiter,
151153
backslash_escape,
152154
);
@@ -155,7 +157,7 @@ fn read_from_stdin(
155157

156158
result
157159
} else {
158-
read_until_from_file(std::io::stdin().as_raw_fd(), delimiter, backslash_escape)
160+
read_until_from_file(stdin().as_raw_fd(), delimiter, backslash_escape)
159161
}
160162
}
161163

sh/src/cli/terminal.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
// SPDX-License-Identifier: MIT
88
//
99

10-
use atty::Stream;
1110
use nix::sys::termios;
1211
use nix::sys::termios::{LocalFlags, Termios};
13-
use std::io;
1412
use std::io::Read;
13+
use std::io::{self, stdin, stdout, IsTerminal};
1514
use std::os::fd::AsFd;
1615

1716
#[derive(Clone)]
@@ -81,5 +80,5 @@ pub fn read_nonblocking_char() -> Option<u8> {
8180
}
8281

8382
pub fn is_attached_to_terminal() -> bool {
84-
atty::is(Stream::Stdin) && atty::is(Stream::Stdout)
83+
stdin().is_terminal() && stdout().is_terminal()
8584
}

0 commit comments

Comments
 (0)