From 4b72d3cc7f10e3ddadc71b5aa37e87a7c2541962 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 24 Nov 2021 10:59:16 -0600 Subject: [PATCH] feat: Color debug output --- src/macros.rs | 9 +++++++-- src/output/fmt.rs | 12 ++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 776431c9..9ee3a3a9 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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(); }) } diff --git a/src/output/fmt.rs b/src/output/fmt.rs index e7da8919..e4317f79 100644 --- a/src/output/fmt.rs +++ b/src/output/fmt.rs @@ -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) { + self.pieces.push((msg.into(), Style::Hint)); + } + #[inline] pub(crate) fn none(&mut self, msg: impl Into) { 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 {