From 5b6c1aa88c43b86479e301244e99be43031b3ab3 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 25 Jun 2024 23:58:25 +0300 Subject: [PATCH] mail/status.rs: don't show all background jobs Information can be retrieved from :manage-jobs tab, so it's redundant to repeat it here. Signed-off-by: Manos Pitsidianakis --- meli/src/mail/status.rs | 48 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/meli/src/mail/status.rs b/meli/src/mail/status.rs index 5d4c606c..15ff2c59 100644 --- a/meli/src/mail/status.rs +++ b/meli/src/mail/status.rs @@ -105,9 +105,15 @@ impl AccountStatus { ); line += 2; - for (job_id, req) in a.active_jobs.iter() { + let mut total = a.active_jobs.len(); + if let Some((job_id, req)) = a + .active_jobs + .iter() + .find(|(_, req)| matches!(req, JobRequest::Watch { .. })) + { + total -= 1; let area = self.content.area().skip(1, line); - let (x, y) = self.content.grid_mut().write_string( + self.content.grid_mut().write_string( &format!("{} {}", req, job_id), self.theme_default.fg, self.theme_default.bg, @@ -116,28 +122,28 @@ impl AccountStatus { None, None, ); - if let JobRequest::DeleteMailbox { mailbox_hash, .. } - | JobRequest::SetMailboxPermissions { mailbox_hash, .. } - | JobRequest::SetMailboxSubscription { mailbox_hash, .. } - | JobRequest::Refresh { mailbox_hash, .. } - | JobRequest::Fetch { mailbox_hash, .. } = req - { - let area = self.content.area().skip(x + 1, y + line); - self.content.grid_mut().write_string( - a.mailbox_entries[mailbox_hash].name(), - self.theme_default.fg, - self.theme_default.bg, - self.theme_default.attrs, - area, - None, - None, - ); - } - line += 1; } - line += 2; + if a.active_jobs.is_empty() || total != 0 { + let area = self.content.area().skip(1, line); + self.content.grid_mut().write_string( + &if a.active_jobs.is_empty() && total == 0 { + Cow::Borrowed("None.") + } else if total == a.active_jobs.len() { + Cow::Owned(format!("{} tasks", total)) + } else { + Cow::Owned(format!("and other {} tasks", total)) + }, + self.theme_default.fg, + self.theme_default.bg, + self.theme_default.attrs, + area, + None, + None, + ); + line += 1; + } let area = self.content.area().skip(1, line); let (_x, _y) = self.content.grid_mut().write_string(