diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-05-01 19:20:33 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:46 +0300 |
commit | fb406667abbd6c776c17c107b51094b0ef3f5c0d (patch) | |
tree | 89b59e8c6c2d04e4bf1f619a371a706780486863 /ui | |
parent | 9143b2e7917437d9b1c245b9fcb85928c0347404 (diff) |
add debug! macro to replace eprintlns
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/contacts/contact_list.rs | 2 | ||||
-rw-r--r-- | ui/src/components/mail/compose.rs | 10 | ||||
-rw-r--r-- | ui/src/components/mail/listing.rs | 5 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 26 | ||||
-rw-r--r-- | ui/src/components/mail/listing/mailbox_view.rs | 23 | ||||
-rw-r--r-- | ui/src/components/mail/listing/plain.rs | 10 | ||||
-rw-r--r-- | ui/src/components/mail/listing/thread.rs | 15 | ||||
-rw-r--r-- | ui/src/components/mail/view/thread.rs | 13 | ||||
-rw-r--r-- | ui/src/components/notifications.rs | 5 | ||||
-rw-r--r-- | ui/src/components/utilities.rs | 3 | ||||
-rw-r--r-- | ui/src/conf/accounts.rs | 20 | ||||
-rw-r--r-- | ui/src/lib.rs | 1 | ||||
-rw-r--r-- | ui/src/state.rs | 16 | ||||
-rw-r--r-- | ui/src/terminal/cells.rs | 26 | ||||
-rw-r--r-- | ui/src/workers.rs | 5 |
15 files changed, 43 insertions, 137 deletions
diff --git a/ui/src/components/contacts/contact_list.rs b/ui/src/components/contacts/contact_list.rs index 3934d50a..35405ada 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 09b02af2..edf41055 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 59b2a9fe..19c63e89 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<FolderHash, Folder> = context.accounts[a.index] diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index a38820ed..a0d45028 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 cbaa8a8f..f455644a 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 93c6764a..8daeba3e 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 1f2e8efc..e496c944 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 52df9c7f..78f0304b 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 2d830fa9..c397f181 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 d9652fa3..35262245 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 1661ca63..08a1c0eb 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<FolderHash, Folder> = self.backend.folders(); return Some(Notification( @@ -284,10 +275,7 @@ impl Account { pub fn list_folders(&self) -> Vec<Folder> { 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 7a8efe2c..fef506a5 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 15dde71e..e2afa8b0 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 f62e2cd7..6075160e 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 debfd16f..d048dd14 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 |