From f61a43108c060c8271fa68bb4358f0872bb36f77 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 11 Sep 2019 18:00:02 +0300 Subject: [PATCH] ui: show worker and static threads in account tab --- ui/src/components/mail/accounts.rs | 154 +++++++++++++++++++++++++---- 1 file changed, 137 insertions(+), 17 deletions(-) diff --git a/ui/src/components/mail/accounts.rs b/ui/src/components/mail/accounts.rs index cde1b375..d68eb74f 100644 --- a/ui/src/components/mail/accounts.rs +++ b/ui/src/components/mail/accounts.rs @@ -24,7 +24,8 @@ use std::fmt; #[derive(Debug)] pub struct AccountsPanel { - cursor: usize, + cursor: (usize, usize), + account_cursor: usize, content: CellBuffer, dirty: bool, id: ComponentId, @@ -42,31 +43,149 @@ impl Component for AccountsPanel { self.initialize(context); self.dirty = false; } - clear_area(grid, area); - let (width, height) = self.content.size(); - copy_area(grid, &self.content, area, ((0, 0), (width - 1, height - 1))); + { + let (_, y) = write_string_to_grid( + "Worker threads", + &mut self.content, + Color::Default, + Color::Default, + Attr::Bold, + ((1, 1), (width - 1, height - 1)), + true, + ); + let mut y = y + 1; + let work_controller = context.work_controller().threads.lock().unwrap(); + let mut workers: Vec<&Worker> = work_controller.values().collect::>(); + let mut max_name = 0; + workers.sort_by_key(|w| { + max_name = std::cmp::max(max_name, w.name.len()); + w.name.as_str() + }); + for worker in workers { + let (x, y_off) = write_string_to_grid( + &format!( + "- {: = work_controller.values().collect::>(); + max_name = 0; + workers.retain(|w| w.name != "WorkController-thread"); + workers.sort_by_key(|w| { + max_name = std::cmp::max(max_name, w.name.len()); + w.name.as_str() + }); + for worker in workers { + let (x, y_off) = write_string_to_grid( + &format!( + "- {: bool { match *event { + UIEvent::Input(Key::Char('k')) => { + self.account_cursor = self.account_cursor.saturating_sub(1); + self.dirty = true; + return true; + } + UIEvent::Input(Key::Char('j')) => { + if self.account_cursor + 1 < context.accounts.len() { + self.account_cursor += 1; + self.dirty = true; + } + return true; + } + UIEvent::Input(Key::Left) => { + self.cursor.0 = self.cursor.0.saturating_sub(1); + self.dirty = true; + return true; + } + UIEvent::Input(Key::Right) => { + self.cursor.0 = self.cursor.0 + 1; + self.dirty = true; + return true; + } UIEvent::Input(Key::Up) => { - self.cursor = self.cursor.saturating_sub(1); + self.cursor.1 = self.cursor.1.saturating_sub(1); self.dirty = true; return true; } UIEvent::Input(Key::Down) => { - if self.cursor + 1 < context.accounts.len() { - self.cursor += 1; - self.dirty = true; - } + self.cursor.1 = self.cursor.1 + 1; + self.dirty = true; return true; } UIEvent::Input(Key::Char('\n')) => { context .replies .push_back(UIEvent::Action(Tab(New(Some(Box::new( - ContactList::for_account(self.cursor), + ContactList::for_account(self.account_cursor), )))))); return true; } @@ -95,10 +214,11 @@ impl Component for AccountsPanel { impl AccountsPanel { pub fn new(context: &Context) -> AccountsPanel { - let content = CellBuffer::new(120, 25 + context.accounts.len() * 20, Cell::default()); + let content = CellBuffer::new(120, 40 + context.accounts.len() * 20, Cell::default()); AccountsPanel { - cursor: 0, + cursor: (0, 0), + account_cursor: 0, content, dirty: true, id: ComponentId::new_v4(), @@ -111,13 +231,13 @@ impl AccountsPanel { Color::Default, Color::Default, Attr::Default, - ((2, 3), (120 - 1, 3)), + ((2, 10), (120 - 1, 10)), true, ); for (i, a) in context.accounts.iter().enumerate() { for x in 2..(120 - 1) { - set_and_join_box(&mut self.content, (x, 5 + i * 10), HORZ_BOUNDARY); + set_and_join_box(&mut self.content, (x, 12 + i * 10), HORZ_BOUNDARY); } //create_box(&mut self.content, ((2, 5 + i * 10), (120 - 1, 15 + i * 10))); let (x, y) = write_string_to_grid( @@ -126,7 +246,7 @@ impl AccountsPanel { Color::Default, Color::Default, Attr::Bold, - ((3, 5 + i * 10), (120 - 2, 5 + i * 10)), + ((3, 12 + i * 10), (120 - 2, 12 + i * 10)), true, ); write_string_to_grid( @@ -135,7 +255,7 @@ impl AccountsPanel { Color::Byte(32), Color::Default, Attr::Default, - ((x, y), (120 - 2, 5 + i * 10)), + ((x, y), (120 - 2, 12 + i * 10)), true, ); write_string_to_grid( @@ -147,7 +267,7 @@ impl AccountsPanel { ((4, y + 2), (120 - 2, y + 2)), true, ); - if i == self.cursor { + if i == self.account_cursor { for h in 1..8 { self.content[(2, h + y + 1)].set_ch('*'); }