diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 37a5c8d..c137fbf 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -259,10 +259,10 @@ impl AppData { /// Get the title for log panel for selected container /// will be "logs x/x" pub fn get_log_title(&self) -> String { - self.get_selected_log_index().map_or( - "".to_owned(), - |index| self.containers.items[index].logs.get_state_title(), - ) + self.get_selected_log_index() + .map_or("".to_owned(), |index| { + self.containers.items[index].logs.get_state_title() + }) } /// select next selected log line @@ -301,6 +301,8 @@ impl AppData { } } + + /// Check if the initial parsing has been completed, by making sure that all ids given (which are running) have a non empty cpu_stats vecdec pub fn initialised(&mut self, all_ids: &[(bool, ContainerId)]) -> bool { let count_is_running = all_ids.iter().filter(|i| i.0).count(); let number_with_cpu_status = self @@ -382,7 +384,7 @@ impl AppData { .collect::>() } - /// find container given id + /// return a mutable container by given id fn get_container_by_id(&mut self, id: &ContainerId) -> Option<&mut ContainerItem> { self.containers.items.iter_mut().find(|i| &i.id == id) } @@ -443,8 +445,10 @@ impl AppData { } } } + // Trim a &String and return String + let trim_owned = |x: &String| x.trim().to_owned(); - for i in all_containers.iter_mut() { + for i in all_containers { if let Some(id) = i.id.as_ref() { let name = i.names.as_mut().map_or("".to_owned(), |names| { names.first_mut().map_or("".to_owned(), |f| { @@ -458,12 +462,12 @@ impl AppData { let state = State::from( i.state .as_ref() - .map_or("dead".to_owned(), |f| f.trim().to_owned()), + .map_or("dead".to_owned(), trim_owned), ); let status = i .status .as_ref() - .map_or("".to_owned(), |f| f.trim().to_owned()); + .map_or("".to_owned(), trim_owned); let image = i .image @@ -512,7 +516,7 @@ impl AppData { container.last_updated = tz; let current_len = container.logs.items.len(); - for i in output.iter() { + for i in output { let lines = if color { log_sanitizer::colorize_logs(i) } else if raw { @@ -523,6 +527,8 @@ impl AppData { container.logs.items.push(ListItem::new(lines)); } + // Set the logs selected row for each container + // Either when no long currently selected, or currently selected (before updated) is already at end if container.logs.state.selected().is_none() || container.logs.state.selected().map_or(1, |f| f + 1) == current_len { diff --git a/src/app_error.rs b/src/app_error.rs index 8770daf..1f90db6 100644 --- a/src/app_error.rs +++ b/src/app_error.rs @@ -17,15 +17,15 @@ pub enum AppError { impl fmt::Display for AppError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Self::DockerCommand(s) => write!(f, "Unable to {} container", s), + Self::DockerCommand(s) => write!(f, "Unable to {} container", s), Self::DockerConnect => write!(f, "Unable to access docker daemon"), Self::DockerInterval => write!(f, "Docker update interval needs to be greater than 0"), Self::InputPoll => write!(f, "Unable to poll user input"), Self::MouseCapture(x) => { - let reason = if *x { "en" } else { "dis" }; + let reason = if *x { "en" } else { "dis" }; write!(f, "Unbale to {}able mouse capture", reason) } - Self::Terminal => write!(f, "Unable to draw to terminal"), + Self::Terminal => write!(f, "Unable to draw to terminal"), } } } diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index dac0021..d0a3e47 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -151,7 +151,7 @@ impl DockerData { /// Update all stats, spawn each container into own tokio::spawn thread fn update_all_container_stats(&mut self, all_ids: &[(bool, ContainerId)]) { - for (is_running, id) in all_ids.iter() { + for (is_running, id) in all_ids { let docker = Arc::clone(&self.docker); let app_data = Arc::clone(&self.app_data); let spawns = Arc::clone(&self.spawns); @@ -185,13 +185,13 @@ impl DockerData { .unwrap_or_default(); let mut output = containers - .iter() + .into_iter() .filter_map(|f| match f.id { Some(_) => { if f.command.as_ref().map_or(false, |c| c.contains("oxker")) { None } else { - Some(f.clone()) + Some(f) } } None => None, @@ -205,13 +205,13 @@ impl DockerData { // Just get the containers that are currently running, or being restarted, no point updating info on paused or dead containers output - .iter() + .into_iter() .filter_map(|i| { - i.id.as_ref().map(|id| { + i.id.map(|id| { ( i.state == Some("running".to_owned()) || i.state == Some("restarting".to_owned()), - ContainerId::from(id.as_str()), + ContainerId::from(id), ) }) }) @@ -253,7 +253,7 @@ impl DockerData { /// Update all logs, spawn each container into own tokio::spawn thread fn init_all_logs(&mut self, all_ids: &[(bool, ContainerId)]) { - for (_, id) in all_ids.iter() { + for (_, id) in all_ids { let docker = Arc::clone(&self.docker); let app_data = Arc::clone(&self.app_data); let spawns = Arc::clone(&self.spawns); diff --git a/src/ui/draw_blocks.rs b/src/ui/draw_blocks.rs index 40dc62c..0dafee3 100644 --- a/src/ui/draw_blocks.rs +++ b/src/ui/draw_blocks.rs @@ -51,7 +51,7 @@ fn generate_block<'a>( panel: SelectablePanel, ) -> Block<'a> { gui_state.lock().update_map(Region::Panel(panel), area); - let current_selected_panel = gui_state.lock().selected_panel; + let current_selected_panel = gui_state.lock().selected_panel; let title = match panel { SelectablePanel::Containers => { format!( @@ -65,10 +65,10 @@ fn generate_block<'a>( } SelectablePanel::Commands => String::from(""), }; - let mut block = Block::default() - .borders(Borders::ALL) - .border_type(BorderType::Rounded) - .title(title); + let mut block = Block::default() + .borders(Borders::ALL) + .border_type(BorderType::Rounded) + .title(title); if current_selected_panel == panel { block = block.border_style(Style::default().fg(Color::LightCyan)); }