summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--melib/Cargo.toml1
-rw-r--r--melib/src/lib.rs43
2 files changed, 24 insertions, 20 deletions
diff --git a/melib/Cargo.toml b/melib/Cargo.toml
index 296ce3f2..cd4309a9 100644
--- a/melib/Cargo.toml
+++ b/melib/Cargo.toml
@@ -25,6 +25,7 @@ bincode = "1.2.0"
uuid = { version = "0.6", features = ["serde", "v4"] }
text_processing = { path = "../text_processing", version = "*", optional= true }
libc = {version = "0.2.59", features = ["extra_traits",]}
+atty = "0.2"
[features]
default = ["unicode_algorithms", "imap_backend", "maildir_backend", "mbox_backend"]
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)*);
}
- };
+ }};
}
}