is-terminal-0.4.13/.cargo_vcs_info.json0000644000000001360000000000100133450ustar { "git": { "sha1": "d51b42d5b30dedeb90bdfb34e6cc6f3b647ea482" }, "path_in_vcs": "" }is-terminal-0.4.13/Cargo.lock0000644000000137320000000000100113260ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi 0.1.19", "libc", "winapi", ] [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "errno" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", ] [[package]] name = "fastrand" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "hermit-abi" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] [[package]] name = "hermit-abi" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" [[package]] name = "is-terminal" version = "0.4.13" dependencies = [ "atty", "hermit-abi 0.4.0", "libc", "rustix", "tempfile", "windows-sys 0.52.0", ] [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "linux-raw-sys" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "rustix" version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys 0.52.0", ] [[package]] name = "tempfile" version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", "fastrand", "once_cell", "rustix", "windows-sys 0.59.0", ] [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets", ] [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" is-terminal-0.4.13/Cargo.toml0000644000000036660000000000100113560ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" rust-version = "1.63" name = "is-terminal" version = "0.4.13" authors = [ "softprops ", "Dan Gohman ", ] build = false include = [ "src", "build.rs", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md", ] autobins = false autoexamples = false autotests = false autobenches = false description = "Test whether a given stream is a terminal" documentation = "https://docs.rs/is-terminal" readme = "README.md" keywords = [ "terminal", "tty", "isatty", ] categories = ["command-line-interface"] license = "MIT" repository = "https://github.com/sunfishcode/is-terminal" [lib] name = "is_terminal" path = "src/lib.rs" [dev-dependencies.atty] version = "0.2.14" [target.'cfg(any(unix, target_os = "wasi"))'.dependencies.libc] version = "0.2" [target.'cfg(any(unix, target_os = "wasi"))'.dev-dependencies.libc] version = "0.2.110" [target.'cfg(any(unix, target_os = "wasi"))'.dev-dependencies.rustix] version = "0.38.0" features = ["termios"] [target.'cfg(not(any(windows, target_os = "hermit", target_os = "unknown")))'.dev-dependencies.rustix] version = "0.38.0" features = ["stdio"] [target.'cfg(target_os = "hermit")'.dependencies.hermit-abi] version = "0.4.0" [target."cfg(windows)".dependencies.windows-sys] version = "0.52.0" features = [ "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_Console", ] [target."cfg(windows)".dev-dependencies.tempfile] version = "3" is-terminal-0.4.13/Cargo.toml.orig000064400000000000000000000023001046102023000150170ustar 00000000000000[package] name = "is-terminal" version = "0.4.13" authors = [ "softprops ", "Dan Gohman " ] description = "Test whether a given stream is a terminal" documentation = "https://docs.rs/is-terminal" repository = "https://github.com/sunfishcode/is-terminal" keywords = ["terminal", "tty", "isatty"] categories = ["command-line-interface"] license = "MIT" edition = "2018" include = ["src", "build.rs", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"] rust-version = "1.63" [target.'cfg(any(unix, target_os = "wasi"))'.dependencies] libc = "0.2" [target.'cfg(target_os = "hermit")'.dependencies] hermit-abi = "0.4.0" [target.'cfg(windows)'.dependencies.windows-sys] version = "0.52.0" features = [ "Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_Console", ] [dev-dependencies] atty = "0.2.14" [target.'cfg(any(unix, target_os = "wasi"))'.dev-dependencies] rustix = { version = "0.38.0", features = ["termios"] } libc = "0.2.110" [target.'cfg(not(any(windows, target_os = "hermit", target_os = "unknown")))'.dev-dependencies] rustix = { version = "0.38.0", features = ["stdio"] } [target.'cfg(windows)'.dev-dependencies] tempfile = "3" is-terminal-0.4.13/LICENSE-MIT000064400000000000000000000017771046102023000136050ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. is-terminal-0.4.13/LICENSE-MIT-atty000064400000000000000000000022301046102023000145450ustar 00000000000000Portions of this project are derived from atty, which bears the following copyright notice and permission notice: Copyright (c) 2015-2019 Doug Tangren Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. is-terminal-0.4.13/README.md000064400000000000000000000070361046102023000134220ustar 00000000000000

is-terminal

Test whether a given stream is a terminal

Github Actions CI Status crates.io page docs.rs docs

As of Rust 1.70, most users should use the [`IsTerminal`] trait in the Rust standard library instead of this crate. On Unix platforms, this crate now uses libc, so that the implementation matches what's in std. Users wishing to use the rustix-based implementation can use the [rustix-is-terminal] crate instead. [rustix-is-terminal]: https://crates.io/crates/rustix-is-terminal
is-terminal is a simple utility that answers one question: > Is this a terminal? A "terminal", also known as a "tty", is an I/O device which may be interactive and may support color and other special features. This crate doesn't provide any of those features; it just answers this one question. On Unix-family platforms, this is effectively the same as the [`isatty`] function for testing whether a given stream is a terminal, though it accepts high-level stream types instead of raw file descriptors. On Windows, it uses a variety of techniques to determine whether the given stream is a terminal. This crate is derived from [the atty crate] with [PR \#51] bug fix and [PR \#54] port to windows-sys applied. The only additional difference is that the atty crate only accepts stdin, stdout, or stderr, while this crate accepts any stream. In particular, this crate does not access any stream that is not passed to it, in accordance with [I/O safety]. [PR \#51]: https://github.com/softprops/atty/pull/51 [PR \#54]: https://github.com/softprops/atty/pull/54 ## Example ```rust use is_terminal::IsTerminal; fn main() { if std::io::stdout().is_terminal() { println!("Stdout is a terminal"); } else { println!("Stdout is not a terminal"); } } ``` ## Testing This library is tested on both Unix-family and Windows platforms. To test it on a platform manually, use the provided `stdio` example program. When run normally, it prints this: ```bash $ cargo run --example stdio stdin? true stdout? true stderr? true ``` To test stdin, pipe some text to the program: ```bash $ cat | cargo run --example stdio stdin? false stdout? true stderr? true ``` To test stdout, pipe the program to something: ```bash $ cargo run --example stdio | cat stdin? true stdout? false stderr? true ``` To test stderr, pipe the program to something redirecting stderr: ```bash $ cargo run --example stdio 2>&1 | cat stdin? true stdout? false stderr? false ``` # Minimum Supported Rust Version (MSRV) This crate currently works on the version of [Rust on Debian stable], which is currently Rust 1.63. This policy may change in the future, in minor version releases, so users using a fixed version of Rust should pin to a specific version of this crate. [`isatty`]: https://man7.org/linux/man-pages/man3/isatty.3.html [the atty crate]: https://crates.io/crates/atty [I/O safety]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md [Rust on Debian stable]: https://packages.debian.org/stable/rust/rustc [`IsTerminal`]: https://doc.rust-lang.org/stable/std/io/trait.IsTerminal.html is-terminal-0.4.13/src/lib.rs000064400000000000000000000231651046102023000140470ustar 00000000000000//! is-terminal is a simple utility that answers one question: //! //! > Is this a terminal? //! //! A "terminal", also known as a "tty", is an I/O device which may be //! interactive and may support color and other special features. This crate //! doesn't provide any of those features; it just answers this one question. //! //! On Unix-family platforms, this is effectively the same as the [`isatty`] //! function for testing whether a given stream is a terminal, though it //! accepts high-level stream types instead of raw file descriptors. //! //! On Windows, it uses a variety of techniques to determine whether the //! given stream is a terminal. //! //! # Example //! //! ```rust //! use is_terminal::IsTerminal; //! //! if std::io::stdout().is_terminal() { //! println!("stdout is a terminal") //! } //! ``` //! //! [`isatty`]: https://man7.org/linux/man-pages/man3/isatty.3.html #![cfg_attr( not(any( unix, windows, target_os = "wasi", target_os = "hermit", target_os = "unknown" )), no_std )] #[cfg(target_os = "hermit")] use std::os::hermit::io::AsFd; #[cfg(unix)] use std::os::unix::io::{AsFd, AsRawFd}; #[cfg(target_os = "wasi")] use std::os::wasi::io::{AsFd, AsRawFd}; #[cfg(windows)] use std::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle}; #[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. /// /// # Example /// /// ``` /// use is_terminal::IsTerminal; /// /// if std::io::stdout().is_terminal() { /// println!("stdout is a terminal") /// } /// ``` 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(any(windows, target_os = "unknown")))] impl IsTerminal for Stream { #[inline] fn is_terminal(&self) -> bool { #[cfg(any(unix, target_os = "wasi"))] { let fd = self.as_fd(); unsafe { libc::isatty(fd.as_raw_fd()) != 0 } } #[cfg(target_os = "hermit")] { use std::os::hermit::io::AsRawFd; hermit_abi::isatty(self.as_fd().as_fd().as_raw_fd()) } } } #[cfg(windows)] impl IsTerminal for Stream { #[inline] fn is_terminal(&self) -> bool { handle_is_console(self.as_handle()) } } // The Windows implementation here is copied from `handle_is_console` in // library/std/src/sys/pal/windows/io.rs in Rust at revision // e74c667a53c6368579867a74494e6fb7a7f17d13. #[cfg(windows)] fn handle_is_console(handle: BorrowedHandle<'_>) -> bool { use windows_sys::Win32::System::Console::GetConsoleMode; let handle = handle.as_raw_handle(); unsafe { // A null handle means the process has no console. if handle.is_null() { return false; } let mut out = 0; if GetConsoleMode(handle as HANDLE, &mut out) != 0 { // False positives aren't possible. If we got a console then we definitely have a console. return true; } // Otherwise, we fall back to an msys hack to see if we can detect the presence of a pty. msys_tty_on(handle as HANDLE) } } /// Returns true if there is an MSYS tty on the given handle. #[cfg(windows)] unsafe fn msys_tty_on(handle: HANDLE) -> bool { use std::ffi::c_void; use windows_sys::Win32::{ Foundation::MAX_PATH, Storage::FileSystem::{ FileNameInfo, GetFileInformationByHandleEx, GetFileType, FILE_TYPE_PIPE, }, }; // Early return if the handle is not a pipe. if GetFileType(handle) != FILE_TYPE_PIPE { return false; } /// Mirrors windows_sys::Win32::Storage::FileSystem::FILE_NAME_INFO, giving /// it a fixed length that we can stack allocate #[repr(C)] #[allow(non_snake_case)] struct FILE_NAME_INFO { FileNameLength: u32, FileName: [u16; MAX_PATH as usize], } let mut name_info = FILE_NAME_INFO { FileNameLength: 0, FileName: [0; MAX_PATH as usize], }; // Safety: buffer length is fixed. let res = GetFileInformationByHandleEx( handle, FileNameInfo, &mut name_info as *mut _ as *mut c_void, std::mem::size_of::() as u32, ); if res == 0 { return false; } // Use `get` because `FileNameLength` can be out of range. let s = match name_info .FileName .get(..name_info.FileNameLength as usize / 2) { None => return false, Some(s) => s, }; let name = String::from_utf16_lossy(s); // Get the file name only. let name = name.rsplit('\\').next().unwrap_or(&name); // This checks whether 'pty' exists in the file name, which indicates that // a pseudo-terminal is attached. To mitigate against false positives // (e.g., an actual file name that contains 'pty'), we also require that // the file name begins with either the strings 'msys-' or 'cygwin-'.) let is_msys = name.starts_with("msys-") || name.starts_with("cygwin-"); let is_pty = name.contains("-pty"); is_msys && is_pty } #[cfg(target_os = "unknown")] impl IsTerminal for std::io::Stdin { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl IsTerminal for std::io::Stdout { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl IsTerminal for std::io::Stderr { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl<'a> IsTerminal for std::io::StdinLock<'a> { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl<'a> IsTerminal for std::io::StdoutLock<'a> { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl<'a> IsTerminal for std::io::StderrLock<'a> { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl<'a> IsTerminal for std::fs::File { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl IsTerminal for std::process::ChildStdin { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl IsTerminal for std::process::ChildStdout { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(target_os = "unknown")] impl IsTerminal for std::process::ChildStderr { #[inline] fn is_terminal(&self) -> bool { false } } #[cfg(test)] mod tests { #[cfg(not(target_os = "unknown"))] use super::IsTerminal; #[test] #[cfg(windows)] fn stdin() { assert_eq!( atty::is(atty::Stream::Stdin), std::io::stdin().is_terminal() ) } #[test] #[cfg(windows)] fn stdout() { assert_eq!( atty::is(atty::Stream::Stdout), std::io::stdout().is_terminal() ) } #[test] #[cfg(windows)] fn stderr() { assert_eq!( atty::is(atty::Stream::Stderr), std::io::stderr().is_terminal() ) } #[test] #[cfg(any(unix, target_os = "wasi"))] fn stdin() { assert_eq!( atty::is(atty::Stream::Stdin), rustix::stdio::stdin().is_terminal() ) } #[test] #[cfg(any(unix, target_os = "wasi"))] fn stdout() { assert_eq!( atty::is(atty::Stream::Stdout), rustix::stdio::stdout().is_terminal() ) } #[test] #[cfg(any(unix, target_os = "wasi"))] fn stderr() { assert_eq!( atty::is(atty::Stream::Stderr), rustix::stdio::stderr().is_terminal() ) } #[test] #[cfg(any(unix, target_os = "wasi"))] fn stdin_vs_libc() { unsafe { assert_eq!( libc::isatty(libc::STDIN_FILENO) != 0, rustix::stdio::stdin().is_terminal() ) } } #[test] #[cfg(any(unix, target_os = "wasi"))] fn stdout_vs_libc() { unsafe { assert_eq!( libc::isatty(libc::STDOUT_FILENO) != 0, rustix::stdio::stdout().is_terminal() ) } } #[test] #[cfg(any(unix, target_os = "wasi"))] fn stderr_vs_libc() { unsafe { assert_eq!( libc::isatty(libc::STDERR_FILENO) != 0, rustix::stdio::stderr().is_terminal() ) } } // Verify that the msys_tty_on function works with long path. #[test] #[cfg(windows)] fn msys_tty_on_path_length() { use std::{fs::File, os::windows::io::AsRawHandle}; use windows_sys::Win32::Foundation::MAX_PATH; let dir = tempfile::tempdir().expect("Unable to create temporary directory"); let file_path = dir.path().join("ten_chars_".repeat(25)); // Ensure that the path is longer than MAX_PATH. assert!(file_path.to_string_lossy().len() > MAX_PATH as usize); let file = File::create(file_path).expect("Unable to create file"); assert!(!unsafe { crate::msys_tty_on(file.as_raw_handle() as isize) }); } }