I'd like to disable colors when the output is piped somewhere else than a terminal.
As of Rust 1.70, std::io::IsTerminal
is available:
use std::io::IsTerminal;
fn main() {
dbg!(std::io::stdout().is_terminal());
}
Alternatively, crossterm has a is_tty() method, and there's also the is-terminal crate (a maintained fork of atty
).