diff --git a/src/lib.rs b/src/lib.rs index 3ca01b0..87a9c3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,6 +38,7 @@ 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. /// @@ -53,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]