From fb406667abbd6c776c17c107b51094b0ef3f5c0d Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 1 May 2019 19:20:33 +0300 Subject: [PATCH] add debug! macro to replace eprintlns --- melib/src/lib.rs | 37 ++++++ melib/src/mailbox.rs | 8 +- melib/src/mailbox/backends/maildir.rs | 28 +---- melib/src/mailbox/backends/maildir/backend.rs | 109 +++++------------- melib/src/mailbox/collection.rs | 60 ++++------ melib/src/mailbox/email.rs | 58 ++++------ melib/src/mailbox/email/attachment_types.rs | 5 +- melib/src/mailbox/email/attachments.rs | 58 +++------- melib/src/mailbox/email/parser.rs | 10 +- melib/src/mailbox/thread.rs | 59 ++++------ src/bin.rs | 2 +- ui/src/components/contacts/contact_list.rs | 2 - ui/src/components/mail/compose.rs | 10 +- ui/src/components/mail/listing.rs | 5 +- ui/src/components/mail/listing/compact.rs | 26 +---- .../components/mail/listing/mailbox_view.rs | 23 +--- ui/src/components/mail/listing/plain.rs | 10 +- ui/src/components/mail/listing/thread.rs | 15 +-- ui/src/components/mail/view/thread.rs | 13 +-- ui/src/components/notifications.rs | 5 +- ui/src/components/utilities.rs | 3 +- ui/src/conf/accounts.rs | 20 +--- ui/src/lib.rs | 1 + ui/src/state.rs | 16 +-- ui/src/terminal/cells.rs | 26 +---- ui/src/workers.rs | 5 +- 26 files changed, 205 insertions(+), 409 deletions(-) diff --git a/melib/src/lib.rs b/melib/src/lib.rs index bf2499170..0df248d24 100644 --- a/melib/src/lib.rs +++ b/melib/src/lib.rs @@ -18,6 +18,43 @@ * You should have received a copy of the GNU General Public License * along with meli. If not, see . */ +#[macro_use] +pub mod dbg { + #[macro_export] + macro_rules! debug { + ($val:expr) => { + if cfg!(debug_assertions) { + eprint!( + "[{:?}] {}:{}_{}: ", + std::thread::current() + .name() + .map(|v| v.to_string()) + .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), + file!(), + line!(), + column!() + ); + eprintln!("{}", $val); + } + }; + ($fmt:literal, $($arg:tt)*) => { + if cfg!(debug_assertions) { + eprint!( + "[{:?}] {}:{}_{}: ", + std::thread::current() + .name() + .map(|v| v.to_string()) + .unwrap_or_else(|| format!("{:?}", std::thread::current().id())), + file!(), + line!(), + column!() + ); + eprintln!($fmt, $($arg)*); + } + }; + } +} + pub mod addressbook; pub mod async_workers; pub mod conf; diff --git a/melib/src/mailbox.rs b/melib/src/mailbox.rs index 7a2c65fa0..ac93cc307 100644 --- a/melib/src/mailbox.rs +++ b/melib/src/mailbox.rs @@ -120,16 +120,12 @@ impl Mailbox { } pub fn insert_reply(&mut self, envelope: &Envelope) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("mailbox insert reply {}", self.name); - } + debug!("mailbox insert reply {}", self.name); self.collection.insert_reply(envelope); } pub fn remove(&mut self, envelope_hash: EnvelopeHash) { self.collection.remove(envelope_hash); - // if cfg!(debug_assertions) { eprint!("{}:{}_{}: ", file!(), line!(), column!()); - // eprintln!("envelope_hash: {}\ncollection:\n{:?}", envelope_hash, self.collection); } + // debug!("envelope_hash: {}\ncollection:\n{:?}", envelope_hash, self.collection); } } diff --git a/melib/src/mailbox/backends/maildir.rs b/melib/src/mailbox/backends/maildir.rs index 8b9c210bc..6cf11f365 100644 --- a/melib/src/mailbox/backends/maildir.rs +++ b/melib/src/mailbox/backends/maildir.rs @@ -66,20 +66,11 @@ impl MaildirOp { fn path(&self) -> PathBuf { let map = self.hash_index.lock().unwrap(); let map = &map[&self.folder_hash]; - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("looking for {} in {} map", self.hash, self.folder_hash); - } + debug!("looking for {} in {} map", self.hash, self.folder_hash); if !map.contains_key(&self.hash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("doesn't contain it though len = {}\n{:#?}", map.len(), map); - } + debug!("doesn't contain it though len = {}\n{:#?}", map.len(), map); for e in map.iter() { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("{:#?}", e); - } + debug!("{:#?}", e); } } map.get(&self.hash).unwrap().clone() @@ -125,8 +116,7 @@ impl<'a> BackendOp for MaildirOp { 'S' => flag |= Flag::SEEN, 'T' => flag |= Flag::TRASHED, _ => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("DEBUG: in fetch_flags, path is {}", path); + debug!("DEBUG: in fetch_flags, path is {}", path); } } } @@ -166,15 +156,9 @@ impl<'a> BackendOp for MaildirOp { new_name.push('T'); } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("renaming {:?} to {:?}", path, new_name); - } + debug!("renaming {:?} to {:?}", path, new_name); fs::rename(&path, &new_name)?; - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("success in rename"); - } + debug!("success in rename"); let old_hash = envelope.hash(); let new_name: PathBuf = new_name.into(); let new_hash = get_file_hash(&new_name); diff --git a/melib/src/mailbox/backends/maildir/backend.rs b/melib/src/mailbox/backends/maildir/backend.rs index 781338dce..b23aab542 100644 --- a/melib/src/mailbox/backends/maildir/backend.rs +++ b/melib/src/mailbox/backends/maildir/backend.rs @@ -137,10 +137,7 @@ fn move_to_cur(p: PathBuf) -> PathBuf { if !file_name.ends_with(":2,") { new.set_extension(":2,"); } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("moved to cur: {}", new.display()); - } + debug!("moved to cur: {}", new.display()); fs::rename(p, &new).unwrap(); new } @@ -161,10 +158,7 @@ impl MailBackend for MaildirType { let root_path = self.path.to_path_buf(); watcher.watch(&root_path, RecursiveMode::Recursive).unwrap(); let cache_dir = xdg::BaseDirectories::with_profile("meli", &self.name).unwrap(); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("watching {:?}", root_path); - } + debug!("watching {:?}", root_path); let hash_indexes = self.hash_indexes.clone(); thread::Builder::new() .name("folder watch".to_string()) @@ -186,11 +180,9 @@ impl MailBackend for MaildirType { Ok(event) => match event { /* Create */ DebouncedEvent::Create(mut pathbuf) => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DebouncedEvent::Create(path = {:?}", pathbuf); + debug!("DebouncedEvent::Create(path = {:?}", pathbuf); if path_is_new!(pathbuf) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("path_is_new"); + debug!("path_is_new"); /* This creates a Rename event that we will receive later */ pathbuf = move_to_cur(pathbuf); } @@ -200,8 +192,6 @@ eprintln!("path_is_new"); .strip_prefix(&root_path) .unwrap() .to_path_buf(); - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("cilename is {:?}", file_name); if let Some(env) = add_path_to_index( &hash_indexes, folder_hash, @@ -209,10 +199,7 @@ eprintln!("cilename is {:?}", file_name); &cache_dir, file_name, ) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("Create event {} {} {}", env.hash(), env.subject(), pathbuf.display()); - } + debug!("Create event {} {} {}", env.hash(), env.subject(), pathbuf.display()); sender.send(RefreshEvent { hash: folder_hash, kind: Create(Box::new(env)), @@ -222,8 +209,7 @@ eprintln!("Create event {} {} {}", env.hash(), env.subject(), pathbuf.display()) /* Update */ DebouncedEvent::NoticeWrite(pathbuf) | DebouncedEvent::Write(pathbuf) => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DebouncedEvent::Write(path = {:?}", pathbuf); + debug!("DebouncedEvent::Write(path = {:?}", &pathbuf); let folder_hash = get_path_hash!(pathbuf); let mut hash_indexes_lock = hash_indexes.lock().unwrap(); let index_lock = &mut hash_indexes_lock.entry(folder_hash).or_default(); @@ -260,14 +246,11 @@ eprintln!("DebouncedEvent::Write(path = {:?}", pathbuf); }; let new_hash: EnvelopeHash = get_file_hash(pathbuf.as_path()); if index_lock.get_mut(&new_hash).is_none() { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("write notice"); + debug!("write notice"); let op = Box::new(MaildirOp::new(new_hash, hash_indexes.clone(), folder_hash)); if let Some(env) = Envelope::from_token(op, new_hash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("{}\t{}", new_hash, pathbuf.display()); - } + debug!("{}\t{:?}", new_hash, &pathbuf); + debug!("hash {}, path: {:?} couldn't be parsed in `add_path_to_index`", new_hash, &pathbuf); index_lock.insert(new_hash, pathbuf); /* Send Write notice */ @@ -276,17 +259,13 @@ eprintln!("{}\t{}", new_hash, pathbuf.display()); hash: folder_hash, kind: Update(old_hash, Box::new(env)), }); - } else if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", new_hash, pathbuf.as_path().display()); } } } /* Remove */ DebouncedEvent::NoticeRemove(pathbuf) | DebouncedEvent::Remove(pathbuf) => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DebouncedEvent::Remove(path = {:?}", pathbuf); + debug!("DebouncedEvent::Remove(path = {:?}", pathbuf); let folder_hash = get_path_hash!(pathbuf); let mut hash_indexes_lock = hash_indexes.lock().unwrap(); let index_lock = hash_indexes_lock.entry(folder_hash).or_default(); @@ -295,8 +274,7 @@ eprintln!("DebouncedEvent::Remove(path = {:?}", pathbuf); { *k } else { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("removed but not contained in index"); + debug!("removed but not contained in index"); continue; }; index_lock.remove(&hash); @@ -308,10 +286,7 @@ eprintln!("removed but not contained in index"); } /* Envelope hasn't changed */ DebouncedEvent::Rename(src, dest) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("DebouncedEvent::Rename(src = {:?}, dest = {:?})", src, dest); - } + debug!("DebouncedEvent::Rename(src = {:?}, dest = {:?})", src, dest); let folder_hash = get_path_hash!(src); let old_hash: EnvelopeHash = get_file_hash(src.as_path()); let new_hash: EnvelopeHash = get_file_hash(dest.as_path()); @@ -320,10 +295,7 @@ eprintln!("removed but not contained in index"); let index_lock = hash_indexes_lock.entry(folder_hash).or_default(); if index_lock.contains_key(&old_hash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("contains_old_key"); - } + debug!("contains_old_key"); sender.send(RefreshEvent { hash: get_path_hash!(dest), kind: Rename(old_hash, new_hash), @@ -332,19 +304,13 @@ eprintln!("removed but not contained in index"); index_lock.insert(new_hash, dest); continue; } else if !index_lock.contains_key(&new_hash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("not contains_new_key"); - } + debug!("not contains_new_key"); let file_name = dest .as_path() .strip_prefix(&root_path) .unwrap() .to_path_buf(); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("filename = {:?}", file_name); - } + debug!("filename = {:?}", file_name); if let Some(env) = add_path_to_index( &hash_indexes, folder_hash, @@ -352,30 +318,21 @@ eprintln!("removed but not contained in index"); &cache_dir, file_name, ) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("Create event {} {} {}", env.hash(), env.subject(), dest.display()); - } + debug!("Create event {} {} {}", env.hash(), env.subject(), dest.display()); sender.send(RefreshEvent { hash: folder_hash, kind: Create(Box::new(env)), }); continue; } else { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("not valid email"); - } + debug!("not valid email"); } } else { sender.send(RefreshEvent { hash: get_path_hash!(dest), kind: Rename(old_hash, new_hash), }); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("contains_new_key"); - } + debug!("contains_new_key"); } /* Maybe a re-read should be triggered here just to be safe. @@ -393,10 +350,7 @@ eprintln!("removed but not contained in index"); _ => {} }, Err(e) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("watch error: {:?}", e) - } + debug!("watch error: {:?}", e) } } } @@ -436,10 +390,7 @@ eprintln!("removed but not contained in index"); hostn_buf.trim() )); } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("saving at {}", path.display()); - } + debug!("saving at {}", path.display()); let file = fs::File::create(path).unwrap(); let mut writer = io::BufWriter::new(file); writer.write_all(bytes).unwrap(); @@ -672,10 +623,7 @@ impl MaildirType { } local_r.push(e); } else { - if cfg!(debug_assertions) { -eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", hash, file.as_path().display()); -} + debug!("DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", hash, file.as_path().display()); continue; } } @@ -710,15 +658,13 @@ fn add_path_to_index( file_name: PathBuf, ) -> Option { let env: Envelope; - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("add_path_to_index path {:?} filename{:?}", path, file_name); + debug!("add_path_to_index path {:?} filename{:?}", path, file_name); let hash = get_file_hash(path); { let mut map = hash_index.lock().unwrap(); let map = map.entry(folder_hash).or_default();; map.insert(hash, path.to_path_buf()); - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!( "inserted {} in {} map, len={}", hash, folder_hash, @@ -727,11 +673,9 @@ fn add_path_to_index( } let op = Box::new(MaildirOp::new(hash, hash_index.clone(), folder_hash)); if let Some(e) = Envelope::from_token(op, hash) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("add_path_to_index gen {}\t{}", hash, file_name.display()); + debug!("add_path_to_index gen {}\t{}", hash, file_name.display()); if let Ok(cached) = cache_dir.place_cache_file(file_name) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("putting in cache"); + debug!("putting in cache"); /* place result in cache directory */ let f = match fs::File::create(cached) { Ok(f) => f, @@ -744,8 +688,7 @@ fn add_path_to_index( } env = e; } else { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!( "DEBUG: hash {}, path: {} couldn't be parsed in `add_path_to_index`", hash, path.display() diff --git a/melib/src/mailbox/collection.rs b/melib/src/mailbox/collection.rs index 7a7f2e339..4dd3ebc04 100644 --- a/melib/src/mailbox/collection.rs +++ b/melib/src/mailbox/collection.rs @@ -52,27 +52,24 @@ impl Collection { let threads = Threads::new(&mut envelopes); /*let cache_dir = - xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash())) - .unwrap(); - if let Some(cached) = cache_dir.find_cache_file("threads") { - let reader = io::BufReader::new(fs::File::open(cached).unwrap()); - let result: result::Result = bincode::deserialize_from(reader); - let ret = if let Ok(mut cached_t) = result { - use std::iter::FromIterator; - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("loaded cache, our hash set is {:?}\n and the cached one is {:?}", FnvHashSet::from_iter(envelopes.keys().cloned()), cached_t.hash_set); - } - cached_t.amend(&mut envelopes); - cached_t - } else { - Threads::new(&mut envelopes) - }; - ret - } else { - Threads::new(&mut envelopes) - }; - */ + xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash())) + .unwrap(); + if let Some(cached) = cache_dir.find_cache_file("threads") { + let reader = io::BufReader::new(fs::File::open(cached).unwrap()); + let result: result::Result = bincode::deserialize_from(reader); + let ret = if let Ok(mut cached_t) = result { + use std::iter::FromIterator; + debug!("loaded cache, our hash set is {:?}\n and the cached one is {:?}", FnvHashSet::from_iter(envelopes.keys().cloned()), cached_t.hash_set); + cached_t.amend(&mut envelopes); + cached_t + } else { + Threads::new(&mut envelopes) + }; + ret + } else { + Threads::new(&mut envelopes) + }; + */ Collection { folder: folder.clone(), @@ -92,10 +89,7 @@ eprintln!("loaded cache, our hash set is {:?}\n and the cached one is {:?}", Fnv } pub fn remove(&mut self, envelope_hash: EnvelopeHash) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DEBUG: Removing {}", envelope_hash); - } + debug!("DEBUG: Removing {}", envelope_hash); self.envelopes.remove(&envelope_hash); self.threads.remove(envelope_hash, &mut self.envelopes); } @@ -145,10 +139,7 @@ eprintln!("DEBUG: Removing {}", envelope_hash); pub fn insert(&mut self, envelope: Envelope) { let hash = envelope.hash(); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("DEBUG: Inserting hash {} in {}", hash, self.folder.name()); - } + debug!("DEBUG: Inserting hash {} in {}", hash, self.folder.name()); self.envelopes.insert(hash, envelope); let env = self.envelopes.entry(hash).or_default() as *mut Envelope; unsafe { @@ -158,13 +149,10 @@ eprintln!("DEBUG: Inserting hash {} in {}", hash, self.folder.name()); pub(crate) fn insert_reply(&mut self, _envelope: &Envelope) { return; /* - //self.insert(envelope); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("insert_reply in collections"); - } - self.threads.insert_reply(envelope, &mut self.envelopes); - */ + //self.insert(envelope); + debug!("insert_reply in collections"); + self.threads.insert_reply(envelope, &mut self.envelopes); + */ } } diff --git a/melib/src/mailbox/email.rs b/melib/src/mailbox/email.rs index ce7a96b7c..9152dcf6c 100644 --- a/melib/src/mailbox/email.rs +++ b/melib/src/mailbox/email.rs @@ -394,10 +394,7 @@ impl Envelope { let (headers, _) = match parser::mail(bytes).to_full_result() { Ok(v) => v, Err(e) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("error in parsing mail\n{:?}\n", e); - } + debug!("error in parsing mail\n{:?}\n", e); let error_msg = String::from("Mail cannot be shown because of errors."); return Err(MeliError::new(error_msg)); } @@ -550,10 +547,7 @@ eprintln!("error in parsing mail\n{:?}\n", e); let (headers, body) = match parser::mail(bytes).to_full_result() { Ok(v) => v, Err(_) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("error in parsing mail\n"); - } + debug!("error in parsing mail\n"); let error_msg = b"Mail cannot be shown because of errors."; let builder = AttachmentBuilder::new(error_msg); return builder.build(); @@ -584,36 +578,32 @@ eprintln!("error in parsing mail\n"); }) } pub fn body(&self, mut operation: Box) -> Attachment { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("searching body for {:?}", self.message_id_display()); + debug!("searching body for {:?}", self.message_id_display()); let file = operation.as_bytes(); self.body_bytes(file.unwrap()) /* - let (headers, body) = match parser::mail(file.unwrap()).to_full_result() { - Ok(v) => v, - Err(_) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("2error in parsing mail\n"); + let (headers, body) = match parser::mail(file.unwrap()).to_full_result() { + Ok(v) => v, + Err(_) => { + debug!("2error in parsing mail\n"); + let error_msg = b"Mail cannot be shown because of errors."; + let mut builder = AttachmentBuilder::new(error_msg); + return builder.build(); + } + }; + let mut builder = AttachmentBuilder::new(body); + for (name, value) in headers { + if value.len() == 1 && value.is_empty() { + continue; + } + if name.eq_ignore_ascii_case(b"content-transfer-encoding") { + builder.content_transfer_encoding(value); + } else if name.eq_ignore_ascii_case(b"content-type") { + builder.content_type(value); + } } - let error_msg = b"Mail cannot be shown because of errors."; - let mut builder = AttachmentBuilder::new(error_msg); - return builder.build(); - } - }; - let mut builder = AttachmentBuilder::new(body); - for (name, value) in headers { - if value.len() == 1 && value.is_empty() { - continue; - } - if name.eq_ignore_ascii_case(b"content-transfer-encoding") { - builder.content_transfer_encoding(value); - } else if name.eq_ignore_ascii_case(b"content-type") { - builder.content_type(value); - } - } - builder.build() - */ + builder.build() + */ } pub fn subject(&self) -> Cow { match self.subject { diff --git a/melib/src/mailbox/email/attachment_types.rs b/melib/src/mailbox/email/attachment_types.rs index 05b486cdf..3a8b8e8c7 100644 --- a/melib/src/mailbox/email/attachment_types.rs +++ b/melib/src/mailbox/email/attachment_types.rs @@ -68,10 +68,7 @@ impl<'a> From<&'a [u8]> for Charset { b"BIG5" | b"big5" => Charset::BIG5, b"ISO-2022-JP" | b"iso-2022-JP" => Charset::ISO2022JP, _ => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("unknown tag is {:?}", str::from_utf8(b)); - } + debug!("unknown tag is {:?}", str::from_utf8(b)); Charset::Ascii } } diff --git a/melib/src/mailbox/email/attachments.rs b/melib/src/mailbox/email/attachments.rs index 3f4877d47..5dd7c28fc 100644 --- a/melib/src/mailbox/email/attachments.rs +++ b/melib/src/mailbox/email/attachments.rs @@ -143,10 +143,7 @@ impl AttachmentBuilder { } } Err(v) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("parsing error in content_type: {:?} {:?}", value, v); - } + debug!("parsing error in content_type: {:?} {:?}", value, v); } } self @@ -212,22 +209,10 @@ eprintln!("parsing error in content_type: {:?} {:?}", value, v); let (headers, body) = match parser::attachment(&a).to_full_result() { Ok(v) => v, Err(_) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("error in parsing attachment"); - } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("\n-------------------------------"); - } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("{}\n", ::std::string::String::from_utf8_lossy(a)); - } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("-------------------------------\n"); - } + debug!("error in parsing attachment"); + debug!("\n-------------------------------"); + debug!("{}\n", ::std::string::String::from_utf8_lossy(a)); + debug!("-------------------------------\n"); continue; } @@ -250,8 +235,7 @@ eprintln!("-------------------------------\n"); vec } a => { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!( + debug!( "error {:?}\n\traw: {:?}\n\tboundary: {:?}", a, str::from_utf8(raw).unwrap(), @@ -400,24 +384,18 @@ fn decode_rfc822(_raw: &[u8]) -> Attachment { builder.build() /* - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("raw is\n{:?}", str::from_utf8(raw).unwrap()); - } - let e = match Envelope::from_bytes(raw) { - Some(e) => e, - None => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("error in parsing mail"); - } - let error_msg = b"Mail cannot be shown because of errors."; - let mut builder = AttachmentBuilder::new(error_msg); - return builder.build(); - } - }; - e.body(None) - */ + debug!("raw is\n{:?}", str::from_utf8(raw).unwrap()); + let e = match Envelope::from_bytes(raw) { + Some(e) => e, + None => { + debug!("error in parsing mail"); + let error_msg = b"Mail cannot be shown because of errors."; + let mut builder = AttachmentBuilder::new(error_msg); + return builder.build(); + } + }; + e.body(None) + */ } type Filter<'a> = Box) -> () + 'a>; diff --git a/melib/src/mailbox/email/parser.rs b/melib/src/mailbox/email/parser.rs index 72439f4b3..3be808e84 100644 --- a/melib/src/mailbox/email/parser.rs +++ b/melib/src/mailbox/email/parser.rs @@ -766,14 +766,8 @@ mod tests { let s = b"Thu, 31 Aug 2017 13:43:37 +0000 (UTC)"; let _s = b"Thu, 31 Aug 2017 13:43:37 +0000"; let __s = b"=?utf-8?q?Thu=2C_31_Aug_2017_13=3A43=3A37_-0000?="; - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("{:?}, {:?}", date(s), date(_s)); - } - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("{:?}", date(__s)); - } + debug!("{:?}, {:?}", date(s), date(_s)); + debug!("{:?}", date(__s)); assert_eq!(date(s).unwrap(), date(_s).unwrap()); assert_eq!(date(_s).unwrap(), date(__s).unwrap()); } diff --git a/melib/src/mailbox/thread.rs b/melib/src/mailbox/thread.rs index 6d8ad2d05..f0de880e5 100644 --- a/melib/src/mailbox/thread.rs +++ b/melib/src/mailbox/thread.rs @@ -574,36 +574,25 @@ impl Threads { t.create_root_set(collection); t.build_collection(collection); - //if cfg!(debug_assertions) { - // for (i, _t) in t.thread_nodes.iter().enumerate() { - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - // eprintln!("Thread #{}, children {}", i, _t.children.len()); - // if !_t.children.is_empty() { - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - // eprintln!("{:?}", _t.children); - // } - // if let Some(m) = _t.message { - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - // eprintln!("\tmessage: {}", collection[&m].subject()); - // } else { - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - // eprintln!("\tNo message"); - // } - // } - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - //eprintln!("\n"); - // for (i, _t) in t.tree.borrow().iter().enumerate() { - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - //eprintln!("Tree #{} id {}, children {}", i, _t.id, _t.children.len()); - // if let Some(m) = t.thread_nodes[_t.id].message { - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - //eprintln!("\tmessage: {}", collection[&m].subject()); - // } else { - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - //eprintln!("\tNo message"); - // } - // } - //} + // for (i, _t) in t.thread_nodes.iter().enumerate() { + // debug!("Thread #{}, children {}", i, _t.children.len()); + // if !_t.children.is_empty() { + // debug!("{:?}", _t.children); + // } + // if let Some(m) = _t.message { + // debug!("\tmessage: {}", collection[&m].subject()); + // } else { + // debug!("\tNo message"); + // } + // } + // for (i, _t) in t.tree.borrow().iter().enumerate() { + // debug!("Tree #{} id {}, children {}", i, _t.id, _t.children.len()); + // if let Some(m) = t.thread_nodes[_t.id].message { + // debug!("\tmessage: {}", collection[&m].subject()); + // } else { + // debug!("\tNo message"); + // } + // } t } @@ -847,10 +836,7 @@ impl Threads { // .iter() // .position(|n| n.message.map(|n| n == envelope_hash).unwrap_or(false)) // .unwrap(); - // if cfg!(debug_assertions) { - // eprint!("{}:{}_{}: ", file!(), line!(), column!()); - // eprintln!("DEBUG: {} in threads is idx= {}", envelope_hash, pos); - // } + // debug!("DEBUG: {} in threads is idx= {}", envelope_hash, pos); //} let t_id: usize; @@ -909,10 +895,7 @@ impl Threads { let difference: Vec = new_hash_set.difference(&self.hash_set).cloned().collect(); for h in difference { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("inserting {}", collection[&h].subject()); - } + debug!("inserting {}", collection[&h].subject()); let env = collection.entry(h).or_default() as *mut Envelope; unsafe { // `collection` is borrowed immutably and `insert` only changes the envelope's diff --git a/src/bin.rs b/src/bin.rs index c1f7fe11e..ec24b838a 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -92,7 +92,7 @@ fn main() { /* Poll on all channels. Currently we have the input channel for stdin, watching events and the signal watcher. */ chan_select! { receiver.recv() -> r => { - match r.unwrap() { + match std::dbg!(r.unwrap()) { ThreadEvent::Input(Key::Ctrl('z')) => { state.switch_to_main_screen(); //_thread_handler.join().expect("Couldn't join on the associated thread"); diff --git a/ui/src/components/contacts/contact_list.rs b/ui/src/components/contacts/contact_list.rs index 3934d50a3..35405ada8 100644 --- a/ui/src/components/contacts/contact_list.rs +++ b/ui/src/components/contacts/contact_list.rs @@ -89,8 +89,6 @@ impl ContactList { maxima.1 = std::cmp::max(maxima.1, c.lastname().split_graphemes().len()); maxima.2 = std::cmp::max(maxima.2, c.email().split_graphemes().len()); maxima.3 = std::cmp::max(maxima.3, c.url().split_graphemes().len()); - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("card = {:?}", c); } maxima.0 += 5; maxima.1 += maxima.0 + 5; diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index 09b02af24..edf410552 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -501,10 +501,7 @@ impl Component for Composer { let account = &context.accounts[self.account_cursor]; let draft = std::mem::replace(&mut self.draft, Draft::default()); if let Err(e) = account.save_draft(draft) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("{:?} could not save draft", e); - } + debug!("{:?} could not save draft", e); context.replies.push_back(UIEvent::Notification( Some("Could not save draft.".into()), e.into(), @@ -559,10 +556,7 @@ impl Component for Composer { .conf() .sent_folder(), ) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("{:?} could not save sent msg", e); - } + debug!("{:?} could not save sent msg", e); context.replies.push_back(UIEvent::Notification( Some("Could not save in 'Sent' folder.".into()), e.into(), diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 59b2a9fe8..19c63e89a 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -470,9 +470,8 @@ impl Listing { a: &AccountMenuEntry, context: &mut Context, ) -> usize { - if cfg!(debug_assertions) && !is_valid_area!(area) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("BUG: invalid area in print_account"); + if !is_valid_area!(area) { + debug!("BUG: invalid area in print_account"); } // Each entry and its index in the account let entries: FnvHashMap = context.accounts[a.index] diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index a38820ede..a0d450289 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -166,20 +166,13 @@ impl MailboxView { threads.thread_nodes()[iter_ptr].message().unwrap() }; if !mailbox.collection.contains_key(&i) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("key = {}", i); - } - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!("key = {}", i); + debug!( "name = {} {}", mailbox.name(), context.accounts[self.cursor_pos.0].name() ); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("{:#?}", context.accounts); - } + debug!("{:#?}", context.accounts); panic!(); } @@ -506,19 +499,13 @@ impl Component for MailboxView { return true; } Action::SubSort(field, order) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("SubSort {:?} , {:?}", field, order); - } + debug!("SubSort {:?} , {:?}", field, order); self.subsort = (*field, *order); self.refresh_mailbox(context); return true; } Action::Sort(field, order) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("Sort {:?} , {:?}", field, order); - } + debug!("Sort {:?} , {:?}", field, order); self.sort = (*field, *order); self.refresh_mailbox(context); return true; @@ -643,8 +630,7 @@ impl CompactListing { impl Component for CompactListing { fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { if !self.populated { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("populating"); + debug!("populating"); for (idx, a) in context.accounts.iter().enumerate() { for (fidx, _) in a.iter_mailboxes().enumerate() { let mut m = MailboxView::new(); diff --git a/ui/src/components/mail/listing/mailbox_view.rs b/ui/src/components/mail/listing/mailbox_view.rs index cbaa8a8f9..f455644aa 100644 --- a/ui/src/components/mail/listing/mailbox_view.rs +++ b/ui/src/components/mail/listing/mailbox_view.rs @@ -160,20 +160,13 @@ impl MailboxView { threads.thread_nodes()[iter_ptr].message().unwrap() }; if !mailbox.collection.contains_key(&i) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("key = {}", i); - } - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!( + debug!("key = {}", i); + debug!( "name = {} {}", mailbox.name(), context.accounts[self.cursor_pos.0].name() ); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("{:#?}", context.accounts); - } + debug!("{:#?}", context.accounts); panic!(); } @@ -462,19 +455,13 @@ impl Component for MailboxView { return true; } Action::SubSort(field, order) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("SubSort {:?} , {:?}", field, order); - } + debug!("SubSort {:?} , {:?}", field, order); self.subsort = (*field, *order); self.refresh_mailbox(context); return true; } Action::Sort(field, order) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("Sort {:?} , {:?}", field, order); - } + debug!("Sort {:?} , {:?}", field, order); self.sort = (*field, *order); self.refresh_mailbox(context); return true; diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs index 93c6764a9..8daeba3ec 100644 --- a/ui/src/components/mail/listing/plain.rs +++ b/ui/src/components/mail/listing/plain.rs @@ -477,20 +477,14 @@ impl Component for PlainListing { return true; } Action::SubSort(field, order) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("SubSort {:?} , {:?}", field, order); - } + debug!("SubSort {:?} , {:?}", field, order); self.subsort = (*field, *order); self.dirty = true; self.refresh_mailbox(context); return true; } Action::Sort(field, order) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("Sort {:?} , {:?}", field, order); - } + debug!("Sort {:?} , {:?}", field, order); self.sort = (*field, *order); self.dirty = true; self.refresh_mailbox(context); diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index 1f2e8efc6..e496c9442 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -489,10 +489,7 @@ impl Component for ThreadListing { let account = &mut context.accounts[self.cursor_pos.0]; let (hash, is_seen) = { let mailbox = &mut account[self.cursor_pos.1].as_mut().unwrap(); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("key is {}", self.locations[dbg!(self.cursor_pos).2]); - } + debug!("key is {}", self.locations[dbg!(self.cursor_pos).2]); let envelope: &Envelope = &mailbox.collection[&self.locations[self.cursor_pos.2]]; (envelope.hash(), envelope.is_seen()) @@ -642,20 +639,14 @@ impl Component for ThreadListing { return true; } Action::SubSort(field, order) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("SubSort {:?} , {:?}", field, order); - } + debug!("SubSort {:?} , {:?}", field, order); self.subsort = (*field, *order); self.dirty = true; self.refresh_mailbox(context); return true; } Action::Sort(field, order) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("Sort {:?} , {:?}", field, order); - } + debug!("Sort {:?} , {:?}", field, order); self.sort = (*field, *order); self.dirty = true; self.refresh_mailbox(context); diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index 52df9c7fe..78f0304b6 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -832,14 +832,11 @@ impl Component for ThreadView { let op = context.accounts[self.coordinates.0] .backend .operation(envelope.hash(), mailbox.folder.hash()); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( - "sending action edit for {}, {}", - envelope.message_id(), - op.description() - ); - } + debug!( + "sending action edit for {}, {}", + envelope.message_id(), + op.description() + ); } context.replies.push_back(UIEvent::Action(Tab(Edit( self.coordinates, diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs index 2d830fa9a..c397f1819 100644 --- a/ui/src/components/notifications.rs +++ b/ui/src/components/notifications.rs @@ -130,10 +130,7 @@ impl Component for NotificationFilter { .stdout(Stdio::piped()) .spawn() { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!("{:?}", v); - } + debug!("{:?}", v); } } } diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index d9652fa30..352622456 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -1072,8 +1072,7 @@ impl Component for Tabbed { self.set_dirty(); return true; } else { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); -eprintln!( + debug!( "DEBUG: Child component with id {:?} not found.\nList: {:?}", id, self.children ); diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index 1661ca636..08a1c0eba 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -134,10 +134,7 @@ impl Account { let notify_fn = Arc::new(notify_fn); if let Some(folder_confs) = settings.conf().folders() { - //if cfg!(debug_assertions) { - //eprint!("{}:{}_{}: ", file!(), line!(), column!()); - //eprintln!("folder renames: {:?}", folder_renames); - //} + //debug!("folder renames: {:?}", folder_renames); for f in ref_folders.values_mut() { if let Some(r) = folder_confs.get(&f.name().to_ascii_lowercase()) { if let Some(rename) = r.rename() { @@ -228,19 +225,13 @@ impl Account { return Some(EnvelopeUpdate(old_hash)); } RefreshEventKind::Rename(old_hash, new_hash) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("rename {} to {}", old_hash, new_hash); - } + debug!("rename {} to {}", old_hash, new_hash); let mailbox = mailbox!(&folder_hash, self.folders); mailbox.rename(old_hash, new_hash); return Some(EnvelopeRename(mailbox.folder.hash(), old_hash, new_hash)); } RefreshEventKind::Create(envelope) => { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("create {}", envelope.hash()); - } + debug!("create {}", envelope.hash()); let env: &Envelope = mailbox!(&folder_hash, self.folders).insert(*envelope); let ref_folders: FnvHashMap = self.backend.folders(); return Some(Notification( @@ -284,10 +275,7 @@ impl Account { pub fn list_folders(&self) -> Vec { let mut folders = self.backend.folders(); if let Some(folder_confs) = self.settings.conf().folders() { - //if cfg!(debug_assertions) { - //eprint!("{}:{}_{}: ", file!(), line!(), column!()); - //eprintln!("folder renames: {:?}", folder_renames); - //} + //debug!("folder renames: {:?}", folder_renames); for f in folders.values_mut() { if let Some(r) = folder_confs.get(&f.name().to_ascii_lowercase()) { if let Some(rename) = r.rename() { diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 7a8efe2c6..fef506a5f 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -23,6 +23,7 @@ * This library exports the public types and methods of its modules */ +#[macro_use] extern crate melib; extern crate mime_apps; extern crate notify_rust; diff --git a/ui/src/state.rs b/ui/src/state.rs index 15dde71e8..e2afa8b07 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -243,16 +243,10 @@ impl State { ) .unwrap(); s.flush(); - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("DEBUG: inserting mailbox hashes:"); - } + debug!("inserting mailbox hashes:"); for (x, account) in s.context.accounts.iter_mut().enumerate() { for folder in account.backend.folders().values() { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("hash & folder: {:?} {}", folder.hash(), folder.name()); - } + debug!("hash & folder: {:?} {}", folder.hash(), folder.name()); s.context.mailbox_hashes.insert(folder.hash(), x); } let sender = s.context.sender.clone(); @@ -293,8 +287,7 @@ impl State { .replies .push_back(UIEvent::MailboxUpdate((idxa, hash))); } else { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!( "BUG: mailbox with hash {} not found in mailbox_hashes.", hash ); @@ -355,8 +348,7 @@ impl State { if termcols.unwrap_or(72) as usize != self.cols || termrows.unwrap_or(120) as usize != self.rows { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!( "Size updated, from ({}, {}) -> ({:?}, {:?})", self.cols, self.rows, termcols, termrows ); diff --git a/ui/src/terminal/cells.rs b/ui/src/terminal/cells.rs index f62e2cd7f..6075160ee 100644 --- a/ui/src/terminal/cells.rs +++ b/ui/src/terminal/cells.rs @@ -574,8 +574,7 @@ pub fn copy_area_with_break( src: Area, ) -> Pos { if !is_valid_area!(dest) || !is_valid_area!(src) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!( "BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}", src, dest ); @@ -622,8 +621,7 @@ pub fn copy_area_with_break( /// Copy a source `Area` to a destination. pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, src: Area) -> Pos { if !is_valid_area!(dest) || !is_valid_area!(src) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!( + debug!( "BUG: Invalid areas in copy_area:\n src: {:?}\n dest: {:?}", src, dest ); @@ -639,10 +637,7 @@ pub fn copy_area(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, dest: Area, let mut src_y = get_y(upper_left!(src)); let (cols, rows) = grid_src.size(); if src_x >= cols || src_y >= rows { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("DEBUG: src area outside of grid_src in copy_area",); - } + debug!("BUG: src area outside of grid_src in copy_area",); return upper_left!(dest); } @@ -679,17 +674,11 @@ pub fn change_colors(grid: &mut CellBuffer, area: Area, fg_color: Color, bg_colo || y >= get_y(bounds) || x >= get_x(bounds) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("BUG: Invalid area in change_colors:\n area: {:?}", area); - } + debug!("BUG: Invalid area in change_colors:\n area: {:?}", area); return; } if !is_valid_area!(area) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("BUG: Invalid area in change_colors:\n area: {:?}", area); - } + debug!("BUG: Invalid area in change_colors:\n area: {:?}", area); return; } for y in get_y(upper_left!(area))..=get_y(bottom_right!(area)) { @@ -739,10 +728,7 @@ pub fn write_string_to_grid( || y > get_y(bounds) || x > get_x(bounds) { - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!(" Invalid area with string {} and area {:?}", s, area); - } + debug!(" Invalid area with string {} and area {:?}", s, area); return (x, y); } for c in s.chars() { diff --git a/ui/src/workers.rs b/ui/src/workers.rs index debfd16fa..d048dd14e 100644 --- a/ui/src/workers.rs +++ b/ui/src/workers.rs @@ -228,10 +228,7 @@ impl WorkController { } // Report the amount of work done. - if cfg!(debug_assertions) { - eprint!("{}:{}_{}: ", file!(), line!(), column!()); - eprintln!("Thread {} did {} jobs.", thread_num, work_done); - } + debug!("Thread {} did {} jobs.", thread_num, work_done); }); // Add the handle for the newly spawned thread to the list of handles