diff options
Diffstat (limited to 'melib/src/lib.rs')
-rw-r--r-- | melib/src/lib.rs | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/melib/src/lib.rs b/melib/src/lib.rs index 38ebfce2..5a74f7ad 100644 --- a/melib/src/lib.rs +++ b/melib/src/lib.rs @@ -25,24 +25,26 @@ pub mod dbg { macro_rules! debug { ($val:literal) => { { - if cfg!(feature="debug-tracing") { - eprint!( - "[{:?}] {}:{}_{}: ", - std::thread::current() - .name() - .map(std::string::ToString::to_string) - .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), - file!(), - line!(), - column!() - ); - eprintln!($val); + use atty; + if atty:is(atty::Stream::Stdout) { + eprint!( + "[{:?}] {}:{}_{}: ", + std::thread::current() + .name() + .map(std::string::ToString::to_string) + .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), + file!(), + line!(), + column!() + ); + eprintln!($val); + } + $val } - $val - } }; - ($val:expr) => { - if cfg!(feature="debug-tracing") { + ($val:expr) => {{ + use atty; + if atty:is(atty::Stream::Stdout) { let stringify = stringify!($val); // Use of `match` here is intentional because it affects the lifetimes // of temporaries - https://stackoverflow.com/a/48732525/1063961 @@ -65,9 +67,10 @@ pub mod dbg { } else { $val } - }; - ($fmt:literal, $($arg:tt)*) => { - if cfg!(feature="debug-tracing") { + }}; + ($fmt:literal, $($arg:tt)*) => {{ + use atty; + if atty:is(atty::Stream::Stdout) { eprint!( "[{:?}] {}:{}_{}: ", std::thread::current() @@ -80,7 +83,7 @@ pub mod dbg { ); eprintln!($fmt, $($arg)*); } - }; + }}; } } |