Skip to main content

tftio_cli_common/
output.rs

1//! Output utilities for consistent terminal formatting.
2
3use is_terminal::IsTerminal;
4use std::io;
5
6/// Check if stdout is a TTY (terminal).
7///
8/// Returns `true` if stdout is connected to a terminal, `false` if piped/redirected.
9/// This is used to determine whether to use colored output and fancy formatting.
10#[must_use]
11pub fn is_tty() -> bool {
12    io::stdout().is_terminal()
13}
14
15/// Check if stderr is a TTY (terminal).
16#[must_use]
17pub fn stderr_is_tty() -> bool {
18    io::stderr().is_terminal()
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    #[test]
26    fn test_is_tty_returns_bool() {
27        // Just verify it returns a boolean without panicking
28        let _result = is_tty();
29        // Function executed successfully if we get here
30    }
31
32    #[test]
33    fn test_stderr_is_tty_returns_bool() {
34        let _result = stderr_is_tty();
35    }
36}