From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/is-terminal/src/lib.rs | 52 +++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'vendor/is-terminal/src/lib.rs') diff --git a/vendor/is-terminal/src/lib.rs b/vendor/is-terminal/src/lib.rs index 18d41e14d..e363f14c1 100644 --- a/vendor/is-terminal/src/lib.rs +++ b/vendor/is-terminal/src/lib.rs @@ -31,11 +31,14 @@ use io_lifetimes::AsFilelike; #[cfg(windows)] use io_lifetimes::BorrowedHandle; +#[cfg(target_os = "hermit")] +use std::os::hermit::io::AsRawFd; #[cfg(windows)] use std::os::windows::io::AsRawHandle; #[cfg(windows)] use windows_sys::Win32::Foundation::HANDLE; +/// Extension trait to check whether something is a terminal. pub trait IsTerminal { /// Returns true if this is a terminal. /// @@ -51,6 +54,23 @@ pub trait IsTerminal { fn is_terminal(&self) -> bool; } +/// Returns `true` if `this` is a terminal. +/// +/// This is equivalent to calling `this.is_terminal()` and exists only as a +/// convenience to calling the trait method [`IsTerminal::is_terminal`] +/// without importing the trait. +/// +/// # Example +/// +/// ``` +/// if is_terminal::is_terminal(&std::io::stdout()) { +/// println!("stdout is a terminal") +/// } +/// ``` +pub fn is_terminal(this: &T) -> bool { + this.is_terminal() +} + #[cfg(not(target_os = "unknown"))] impl IsTerminal for Stream { #[inline] @@ -62,7 +82,7 @@ impl IsTerminal for Stream { #[cfg(target_os = "hermit")] { - hermit_abi::isatty(self.as_filelike().as_fd()) + hermit_abi::isatty(self.as_filelike().as_raw_fd()) } #[cfg(windows)] @@ -291,34 +311,28 @@ mod tests { #[test] #[cfg(any(unix, target_os = "wasi"))] fn stdin() { - unsafe { - assert_eq!( - atty::is(atty::Stream::Stdin), - rustix::io::stdin().is_terminal() - ) - } + assert_eq!( + atty::is(atty::Stream::Stdin), + rustix::io::stdin().is_terminal() + ) } #[test] #[cfg(any(unix, target_os = "wasi"))] fn stdout() { - unsafe { - assert_eq!( - atty::is(atty::Stream::Stdout), - rustix::io::stdout().is_terminal() - ) - } + assert_eq!( + atty::is(atty::Stream::Stdout), + rustix::io::stdout().is_terminal() + ) } #[test] #[cfg(any(unix, target_os = "wasi"))] fn stderr() { - unsafe { - assert_eq!( - atty::is(atty::Stream::Stderr), - rustix::io::stderr().is_terminal() - ) - } + assert_eq!( + atty::is(atty::Stream::Stderr), + rustix::io::stderr().is_terminal() + ) } #[test] -- cgit v1.2.3