tealdeer/src/utils.rs
Blair Noctis fb7492b0b5
Upgrade yansi: 0.5.1 -> 1.0.1 (#389)
- Adapt to `thing.paint(style)` API; was `style.paint(thing)`
- Remove `yansi::Paint::enable_windows_ascii()` in style usage decision;
  removed in yansi commit b186eb5bfb, which introduced "automatic"
  support for Windows: "If support is not available, styling is disabled
  and no styling sequences are emitted", fitting the `Auto` option
- Respect `--color=always` even if we know it won't work

---------

Co-authored-by: Niklas Mohrin <dev@niklasmohrin.de>
2024-11-14 16:07:30 +01:00

21 lines
741 B
Rust

use yansi::{Color, Paint};
/// Print a warning to stderr. If `enable_styles` is true, then a yellow
/// message will be printed.
pub fn print_warning(enable_styles: bool, message: &str) {
print_msg(enable_styles, message, "Warning: ", Color::Yellow);
}
/// Print an anyhow error to stderr. If `enable_styles` is true, then a red
/// message will be printed.
pub fn print_error(enable_styles: bool, error: &anyhow::Error) {
print_msg(enable_styles, &format!("{error:?}"), "Error: ", Color::Red);
}
fn print_msg(enable_styles: bool, message: &str, prefix: &'static str, color: Color) {
if enable_styles {
eprintln!("{}{}", prefix.paint(color), message.paint(color));
} else {
eprintln!("{message}");
}
}