mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
feat: Color debug output
This commit is contained in:
parent
463d75474e
commit
4b72d3cc7f
2 changed files with 17 additions and 4 deletions
|
@ -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();
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue