New API to disable ANSI escape code emission on redirected outputs.
see #921
Example of code provided by this feature:
fn print_diagnostic() {
let _guard = style::disable_ansi(!io::stderr().is_terminal());
// styling stderr output is now only active if stderr is not redirected
eprintln!("{}: {}", "error".red().bold(), "something went wrong".bold());
}
A nice thing is that the code that prints doesn't need to be aware of the feature and can use the fmt API and be in a different crate.
New API to disable ANSI escape code emission on redirected outputs. see #921
Example of code provided by this feature:
A nice thing is that the code that prints doesn't need to be aware of the feature and can use the fmt API and be in a different crate.
New API is behind a cargo feature because there is a runtime check for each escape code emitted. Not everyone wants to pay this cost.
Without this PR, managing redirected output is tedious and generally requires to double the print code. (with and without style)