mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-09 09:49:10 +02:00
- 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>
21 lines
741 B
Rust
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}");
|
|
}
|
|
}
|