pub fn process_error_output(result: Result<()>) -> Result<()>Expand description
Processes and formats error output for display to the user.
This function takes a Result and handles error display appropriately based on
whether the output is directed to a TTY (terminal) or not. When outputting to
a terminal, errors are displayed in red color for better visibility.
§Arguments
result- AResult<()>to process. If it’s anErr, the error will be formatted and written to stderr.
§Returns
Always returns Ok(()) regardless of the input result. The actual error
handling is done by writing to stderr.
§Behavior
- Success case: Does nothing and returns
Ok(()) - Error case with TTY: Writes the error to stderr in red color
- Error case without TTY: Writes the error to stderr in plain text
§Examples
use xdiff_live::process_error_output;
use anyhow::Result;
fn might_fail() -> Result<()> {
Err(anyhow::anyhow!("Something went wrong"))
}
let result = might_fail();
process_error_output(result).unwrap();§Note
This function uses the atty crate to detect if stderr is connected to a TTY,
allowing it to provide colored output when appropriate while maintaining
compatibility with non-interactive environments.