Skip to content

Commit 594aa1e

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

File tree

5 files changed

+13
-36
lines changed

5 files changed

+13
-36
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ There are several ways to contribute to posixutils-rs:
1414
3. Test coverage: Integration tests, positive and negative, are complete, pass 100%
1515
4. Code coverage: Automated code coverage data indicates 100%
1616
5. Translated: All strings are internationalized, including common OS errors for common error cases.
17-
6. Audited: An external party has reviewed and tested for correctness,
17+
6. Audited: An external party has reviewed and tested for correctness,
1818
POSIX compliance, security, races and similar issues.
1919

2020
### Coding considerations
@@ -29,12 +29,11 @@ There are several ways to contribute to posixutils-rs:
2929
### CLI utility and Rust style guidelines
3030

3131
1. `cargo fmt` is required.
32-
2. Ideal goal: **Each utility should look like a standard Rust CLI program.**
32+
2. Ideal goal: **Each utility should look like a standard Rust CLI program.**
3333
Small, lightweight utility with command line processing,
3434
core algorithm, and zero external crate dependencies.
3535
3. "only std" When an external crate is required, avoid mega-crates. Prefer
36-
std-only, or, tiny crates such as `atty` that perform a single,
37-
lightweight function.
36+
std-only, or, tiny crates that perform a single, lightweight function.
3837
4. Correctness, readability, performance, in that order.
3938
Code should be readable by unfamiliar developers. Avoid dense,
4039
uncommented code.
@@ -58,4 +57,3 @@ There are several ways to contribute to posixutils-rs:
5857
* Provide any input data can that be used to reproduce the bug.
5958
* Provide any error output from the utility.
6059
* Describe expected results: What did you expect to happen, and did not?
61-

Cargo.lock

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sh/Cargo.toml

Lines changed: 0 additions & 1 deletion
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

Lines changed: 8 additions & 6 deletions
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

Lines changed: 2 additions & 3 deletions
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)