Skip to content

Conversation

@joshka
Copy link

@joshka joshka commented Apr 3, 2025

IsTerminal trait was introduced in Rust 1.70

Comment on lines -18 to +21
use std::os::fd::{AsRawFd, RawFd};
use std::time::Duration;
use std::{io::stdin, time::Duration};
use std::{
io::IsTerminal,
os::fd::{AsRawFd, RawFd},
};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was cargo fmt - I didn't review it. Perhaps consider going with the same decision as the rust standard library does and configuring a rustfmt.toml to group imports by module? This tends to cut down a large number of lines and makes diffs simpler generally.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgarzik
Copy link
Contributor

jgarzik commented Apr 3, 2025

Thanks for the patch.

Quick review: ok, but should be applied across entire tree. We don't want to avoid atty in one util, yet use atty in another util.

IsTerminal trait was introduced in Rust 1.70
@joshka
Copy link
Author

joshka commented Apr 3, 2025

Quick review: ok, but should be applied across entire tree. We don't want to avoid atty in one util, yet use atty in another util.

This was the only instance of the atty crate in the main branch (are the other branches active development?).
The atty crate is no longer in the cargo.lock at all:
https://github.com/rustcoreutils/posixutils-rs/blob/fa17a3118e4bfbf3c19e7f04599e8fa80e5d288a/Cargo.lock

There are some calls to use libc::isatty not included in this change (will make another PR), and mention of atty in the contributing doc (which I've removed in 594aa1e).

@joshka
Copy link
Author

joshka commented Apr 3, 2025

Actually - the replacement for the libc::isatty call was relatively simple.

76fa884
cf26e81 - removed libc from the deps for test

Manually tested this with:

target/debug/test -t 0 || echo foo
echo foo target/debug/test -t 0 || echo foo # no output
target/debug/test -t 1 || echo foo
target/debug/test -t 1 1&>/dev/null || echo foo # no output
target/debug/test -t 2 || echo foo
target/debug/test -t 2 2&>/dev/null || echo foo # no output
target/debug/test -t 3 || echo foo # no output
target/debug/test -t 3 3&>/dev/tty || echo foo
target/debug/test -t asdf || echo foo # no output

@jgarzik
Copy link
Contributor

jgarzik commented Dec 1, 2025

thanks - looks like rust std isTerminal is the best approach

@jgarzik jgarzik closed this Dec 1, 2025
@joshka
Copy link
Author

joshka commented Dec 1, 2025

I'm not sure I follow. Using IsTerminal is what this PR does.

@joshka
Copy link
Author

joshka commented Dec 16, 2025

Hey, I'm not sure I understand why this was closed. You wrote that "rust std isTerminal is the best approach", that's what this PR does.

@jgarzik
Copy link
Contributor

jgarzik commented Dec 16, 2025

This was closed because the upstream tree uses is_terminal, and no longer requires atty crate anywhere.

@joshka
Copy link
Author

joshka commented Dec 19, 2025

This was closed because the upstream tree uses is_terminal, and no longer requires atty crate anywhere.

Got it. No biggy, but this also removes the libc requirement due to:

posixutils-rs/misc/test.rs

Lines 166 to 169 in 67ed41f

// Normally, posixutils would use the atty crate.
// Passing an arbitrary fd requires unsafe isatty in this case.
unsafe { libc::isatty(fd as i32) == 1 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants