feat: Color debug output

This commit is contained in:
Ed Page 2021-11-24 10:59:16 -06:00
parent 463d75474e
commit 4b72d3cc7f
2 changed files with 17 additions and 4 deletions

View file

@ -805,8 +805,13 @@ macro_rules! wlnerr {
#[cfg(feature = "debug")]
macro_rules! debug {
($($arg:tt)*) => ({
print!("[{:>w$}] \t", module_path!(), w = 28);
println!($($arg)*);
let prefix = format!("[{:>w$}] \t", module_path!(), w = 28);
let body = format!($($arg)*);
let mut color = $crate::output::fmt::Colorizer::new(true, $crate::ColorChoice::Auto);
color.hint(prefix);
color.hint(body);
color.none("\n");
let _ = color.print();
})
}

View file

@ -37,6 +37,12 @@ impl Colorizer {
self.pieces.push((msg.into(), Style::Error));
}
#[inline]
#[allow(dead_code)]
pub(crate) fn hint(&mut self, msg: impl Into<String>) {
self.pieces.push((msg.into(), Style::Hint));
}
#[inline]
pub(crate) fn none(&mut self, msg: impl Into<String>) {
self.pieces.push((msg.into(), Style::Default));
@ -76,6 +82,9 @@ impl Colorizer {
color.set_fg(Some(termcolor::Color::Red));
color.set_bold(true);
}
Style::Hint => {
color.set_dimmed(true);
}
Style::Default => {}
}
@ -119,6 +128,7 @@ pub enum Style {
Good,
Warning,
Error,
Hint,
Default,
}
@ -130,8 +140,6 @@ impl Default for Style {
#[cfg(feature = "color")]
fn is_a_tty(stderr: bool) -> bool {
debug!("is_a_tty: stderr={:?}", stderr);
let stream = if stderr {
atty::Stream::Stderr
} else {