]> git.proxmox.com Git - rustc.git/blobdiff - vendor/is-terminal/src/lib.rs
New upstream version 1.72.1+dfsg1
[rustc.git] / vendor / is-terminal / src / lib.rs
index e363f14c11d14873316a41457099b0925122aa7b..e68e60ffaa0e667aa26557be7e3931ecba835020 100644 (file)
 
 #![cfg_attr(unix, no_std)]
 
-#[cfg(not(target_os = "unknown"))]
-use io_lifetimes::AsFilelike;
-#[cfg(windows)]
-use io_lifetimes::BorrowedHandle;
+#[cfg(not(any(windows, target_os = "unknown")))]
+use rustix::fd::AsFd;
 #[cfg(target_os = "hermit")]
 use std::os::hermit::io::AsRawFd;
 #[cfg(windows)]
-use std::os::windows::io::AsRawHandle;
+use std::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle};
 #[cfg(windows)]
 use windows_sys::Win32::Foundation::HANDLE;
 
@@ -67,12 +65,12 @@ pub trait IsTerminal {
 ///     println!("stdout is a terminal")
 /// }
 /// ```
-pub fn is_terminal<T: IsTerminal>(this: &T) -> bool {
+pub fn is_terminal<T: IsTerminal>(this: T) -> bool {
     this.is_terminal()
 }
 
-#[cfg(not(target_os = "unknown"))]
-impl<Stream: AsFilelike> IsTerminal for Stream {
+#[cfg(not(any(windows, target_os = "unknown")))]
+impl<Stream: AsFd> IsTerminal for Stream {
     #[inline]
     fn is_terminal(&self) -> bool {
         #[cfg(any(unix, target_os = "wasi"))]
@@ -82,13 +80,16 @@ impl<Stream: AsFilelike> IsTerminal for Stream {
 
         #[cfg(target_os = "hermit")]
         {
-            hermit_abi::isatty(self.as_filelike().as_raw_fd())
+            hermit_abi::isatty(self.as_fd().as_raw_fd())
         }
+    }
+}
 
-        #[cfg(windows)]
-        {
-            handle_is_console(self.as_filelike())
-        }
+#[cfg(windows)]
+impl<Stream: AsHandle> IsTerminal for Stream {
+    #[inline]
+    fn is_terminal(&self) -> bool {
+        handle_is_console(self.as_handle())
     }
 }
 
@@ -313,7 +314,7 @@ mod tests {
     fn stdin() {
         assert_eq!(
             atty::is(atty::Stream::Stdin),
-            rustix::io::stdin().is_terminal()
+            rustix::stdio::stdin().is_terminal()
         )
     }
 
@@ -322,7 +323,7 @@ mod tests {
     fn stdout() {
         assert_eq!(
             atty::is(atty::Stream::Stdout),
-            rustix::io::stdout().is_terminal()
+            rustix::stdio::stdout().is_terminal()
         )
     }
 
@@ -331,7 +332,7 @@ mod tests {
     fn stderr() {
         assert_eq!(
             atty::is(atty::Stream::Stderr),
-            rustix::io::stderr().is_terminal()
+            rustix::stdio::stderr().is_terminal()
         )
     }
 
@@ -341,7 +342,7 @@ mod tests {
         unsafe {
             assert_eq!(
                 libc::isatty(libc::STDIN_FILENO) != 0,
-                rustix::io::stdin().is_terminal()
+                rustix::stdio::stdin().is_terminal()
             )
         }
     }
@@ -352,7 +353,7 @@ mod tests {
         unsafe {
             assert_eq!(
                 libc::isatty(libc::STDOUT_FILENO) != 0,
-                rustix::io::stdout().is_terminal()
+                rustix::stdio::stdout().is_terminal()
             )
         }
     }
@@ -363,7 +364,7 @@ mod tests {
         unsafe {
             assert_eq!(
                 libc::isatty(libc::STDERR_FILENO) != 0,
-                rustix::io::stderr().is_terminal()
+                rustix::stdio::stderr().is_terminal()
             )
         }
     }