| 1 | //! > Polyfill for `is_terminal` stdlib feature for use with older MSRVs |
| 2 | |
| 3 | #![warn(clippy::print_stderr)] |
| 4 | #![warn(clippy::print_stdout)] |
| 5 | |
| 6 | /// Trait to determine if a descriptor/handle refers to a terminal/tty. |
| 7 | pub trait IsTerminalrust-analyzer cargo is_terminal_polyfill 1.70.2 IsTerminal#: sealedrust-analyzer cargo is_terminal_polyfill 1.70.2 sealed/::Sealedrust-analyzer cargo is_terminal_polyfill 1.70.2 sealed/Sealed# { |
| 8 | /// Returns `true` if the descriptor/handle refers to a terminal/tty. |
| 9 | /// |
| 10 | /// On platforms where Rust does not know how to detect a terminal yet, this will return |
| 11 | /// `false`. This will also return `false` if an unexpected error occurred, such as from |
| 12 | /// passing an invalid file descriptor. |
| 13 | /// |
| 14 | /// # Platform-specific behavior |
| 15 | /// |
| 16 | /// On Windows, in addition to detecting consoles, this currently uses some heuristics to |
| 17 | /// detect older msys/cygwin/mingw pseudo-terminals based on device name: devices with names |
| 18 | /// starting with `msys-` or `cygwin-` and ending in `-pty` will be considered terminals. |
| 19 | /// Note that this [may change in the future][changes]. |
| 20 | /// |
| 21 | /// [changes]: std::io#platform-specific-behavior |
| 22 | fn is_terminalrust-analyzer cargo is_terminal_polyfill 1.70.2 IsTerminal#is_terminal().(&self) -> bool; |
| 23 | } |
| 24 | |
| 25 | mod sealedrust-analyzer cargo is_terminal_polyfill 1.70.2 sealed/ { |
| 26 | pub trait Sealedrust-analyzer cargo is_terminal_polyfill 1.70.2 sealed/Sealed# {} |
| 27 | } |
| 28 | |
| 29 | macro_rules! impl_is_terminalrust-analyzer cargo is_terminal_polyfill 1.70.2 impl_is_terminal! { |
| 30 | ($($t:ty),*$(,)?) => {$( |
| 31 | impl sealed::Sealed for $t {} |
| 32 | |
| 33 | impl IsTerminal for $t { |
| 34 | #[inline] |
| 35 | fn is_terminal(&self) -> bool { |
| 36 | std::io::IsTerminal::is_terminal(self) |
| 37 | } |
| 38 | } |
| 39 | )*} |
| 40 | } |
| 41 | |
| 42 | impl_is_terminalrust-analyzer cargo is_terminal_polyfill 1.70.2 impl_is_terminal!!( |
| 43 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#, |
| 44 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/Stdin#, |
| 45 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::StdinLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/StdinLock#<'_>, |
| 46 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/Stdout#, |
| 47 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::StdoutLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/StdoutLock#<'_>, |
| 48 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/Stderr#, |
| 49 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::StderrLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/StderrLock#<'_> |
| 50 | ); |