Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io: implement is_terminal for stdio types #7114

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

maminrayej
Copy link
Member

This PR adds the is_terminal function to different stdio types by delegating to the IsTerminal::is_terminal implementation of the standard library. Note that since this trait is sealed, we cannot implement it directly.

Resolves #6407.

@maminrayej maminrayej added A-tokio Area: The main tokio crate M-io Module: tokio/io M-process Module: tokio/process labels Jan 19, 2025
Comment on lines +138 to +144
/// Returns true if the descriptor/handle refers to a terminal/tty.
pub fn is_terminal(&self) -> bool {
self.std
.inner()
.inner()
.map(|stderr| stderr.is_terminal())
.unwrap_or_default()
Copy link
Contributor

Choose a reason for hiding this comment

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

This will incorrectly return false if stderr is a terminal but there is an ongoing IO operation. Can we instead do this?

Suggested change
/// Returns true if the descriptor/handle refers to a terminal/tty.
pub fn is_terminal(&self) -> bool {
self.std
.inner()
.inner()
.map(|stderr| stderr.is_terminal())
.unwrap_or_default()
/// Returns true if the descriptor/handle refers to a terminal/tty.
pub fn is_terminal(&self) -> bool {
std::io::stderr().is_terminal()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-io Module: tokio/io M-process Module: tokio/process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing IsTerminal::is_terminal for files and stdin
2 participants