refactor: replace iter() to into_iter(), and remove useless .iters()'s
This commit is contained in:
+15
-9
@@ -259,10 +259,10 @@ impl AppData {
|
|||||||
/// Get the title for log panel for selected container
|
/// Get the title for log panel for selected container
|
||||||
/// will be "logs x/x"
|
/// will be "logs x/x"
|
||||||
pub fn get_log_title(&self) -> String {
|
pub fn get_log_title(&self) -> String {
|
||||||
self.get_selected_log_index().map_or(
|
self.get_selected_log_index()
|
||||||
"".to_owned(),
|
.map_or("".to_owned(), |index| {
|
||||||
|index| self.containers.items[index].logs.get_state_title(),
|
self.containers.items[index].logs.get_state_title()
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// select next selected log line
|
/// 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 {
|
pub fn initialised(&mut self, all_ids: &[(bool, ContainerId)]) -> bool {
|
||||||
let count_is_running = all_ids.iter().filter(|i| i.0).count();
|
let count_is_running = all_ids.iter().filter(|i| i.0).count();
|
||||||
let number_with_cpu_status = self
|
let number_with_cpu_status = self
|
||||||
@@ -382,7 +384,7 @@ impl AppData {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// find container given id
|
/// return a mutable container by given id
|
||||||
fn get_container_by_id(&mut self, id: &ContainerId) -> Option<&mut ContainerItem> {
|
fn get_container_by_id(&mut self, id: &ContainerId) -> Option<&mut ContainerItem> {
|
||||||
self.containers.items.iter_mut().find(|i| &i.id == id)
|
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() {
|
if let Some(id) = i.id.as_ref() {
|
||||||
let name = i.names.as_mut().map_or("".to_owned(), |names| {
|
let name = i.names.as_mut().map_or("".to_owned(), |names| {
|
||||||
names.first_mut().map_or("".to_owned(), |f| {
|
names.first_mut().map_or("".to_owned(), |f| {
|
||||||
@@ -458,12 +462,12 @@ impl AppData {
|
|||||||
let state = State::from(
|
let state = State::from(
|
||||||
i.state
|
i.state
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or("dead".to_owned(), |f| f.trim().to_owned()),
|
.map_or("dead".to_owned(), trim_owned),
|
||||||
);
|
);
|
||||||
let status = i
|
let status = i
|
||||||
.status
|
.status
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or("".to_owned(), |f| f.trim().to_owned());
|
.map_or("".to_owned(), trim_owned);
|
||||||
|
|
||||||
let image = i
|
let image = i
|
||||||
.image
|
.image
|
||||||
@@ -512,7 +516,7 @@ impl AppData {
|
|||||||
container.last_updated = tz;
|
container.last_updated = tz;
|
||||||
let current_len = container.logs.items.len();
|
let current_len = container.logs.items.len();
|
||||||
|
|
||||||
for i in output.iter() {
|
for i in output {
|
||||||
let lines = if color {
|
let lines = if color {
|
||||||
log_sanitizer::colorize_logs(i)
|
log_sanitizer::colorize_logs(i)
|
||||||
} else if raw {
|
} else if raw {
|
||||||
@@ -523,6 +527,8 @@ impl AppData {
|
|||||||
container.logs.items.push(ListItem::new(lines));
|
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()
|
if container.logs.state.selected().is_none()
|
||||||
|| container.logs.state.selected().map_or(1, |f| f + 1) == current_len
|
|| container.logs.state.selected().map_or(1, |f| f + 1) == current_len
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-3
@@ -17,15 +17,15 @@ pub enum AppError {
|
|||||||
impl fmt::Display for AppError {
|
impl fmt::Display for AppError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
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::DockerConnect => write!(f, "Unable to access docker daemon"),
|
||||||
Self::DockerInterval => write!(f, "Docker update interval needs to be greater than 0"),
|
Self::DockerInterval => write!(f, "Docker update interval needs to be greater than 0"),
|
||||||
Self::InputPoll => write!(f, "Unable to poll user input"),
|
Self::InputPoll => write!(f, "Unable to poll user input"),
|
||||||
Self::MouseCapture(x) => {
|
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)
|
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"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ impl DockerData {
|
|||||||
|
|
||||||
/// Update all stats, spawn each container into own tokio::spawn thread
|
/// Update all stats, spawn each container into own tokio::spawn thread
|
||||||
fn update_all_container_stats(&mut self, all_ids: &[(bool, ContainerId)]) {
|
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 docker = Arc::clone(&self.docker);
|
||||||
let app_data = Arc::clone(&self.app_data);
|
let app_data = Arc::clone(&self.app_data);
|
||||||
let spawns = Arc::clone(&self.spawns);
|
let spawns = Arc::clone(&self.spawns);
|
||||||
@@ -185,13 +185,13 @@ impl DockerData {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut output = containers
|
let mut output = containers
|
||||||
.iter()
|
.into_iter()
|
||||||
.filter_map(|f| match f.id {
|
.filter_map(|f| match f.id {
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
if f.command.as_ref().map_or(false, |c| c.contains("oxker")) {
|
if f.command.as_ref().map_or(false, |c| c.contains("oxker")) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(f.clone())
|
Some(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => None,
|
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
|
// Just get the containers that are currently running, or being restarted, no point updating info on paused or dead containers
|
||||||
output
|
output
|
||||||
.iter()
|
.into_iter()
|
||||||
.filter_map(|i| {
|
.filter_map(|i| {
|
||||||
i.id.as_ref().map(|id| {
|
i.id.map(|id| {
|
||||||
(
|
(
|
||||||
i.state == Some("running".to_owned())
|
i.state == Some("running".to_owned())
|
||||||
|| i.state == Some("restarting".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
|
/// Update all logs, spawn each container into own tokio::spawn thread
|
||||||
fn init_all_logs(&mut self, all_ids: &[(bool, ContainerId)]) {
|
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 docker = Arc::clone(&self.docker);
|
||||||
let app_data = Arc::clone(&self.app_data);
|
let app_data = Arc::clone(&self.app_data);
|
||||||
let spawns = Arc::clone(&self.spawns);
|
let spawns = Arc::clone(&self.spawns);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ fn generate_block<'a>(
|
|||||||
panel: SelectablePanel,
|
panel: SelectablePanel,
|
||||||
) -> Block<'a> {
|
) -> Block<'a> {
|
||||||
gui_state.lock().update_map(Region::Panel(panel), area);
|
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 {
|
let title = match panel {
|
||||||
SelectablePanel::Containers => {
|
SelectablePanel::Containers => {
|
||||||
format!(
|
format!(
|
||||||
@@ -65,10 +65,10 @@ fn generate_block<'a>(
|
|||||||
}
|
}
|
||||||
SelectablePanel::Commands => String::from(""),
|
SelectablePanel::Commands => String::from(""),
|
||||||
};
|
};
|
||||||
let mut block = Block::default()
|
let mut block = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.title(title);
|
.title(title);
|
||||||
if current_selected_panel == panel {
|
if current_selected_panel == panel {
|
||||||
block = block.border_style(Style::default().fg(Color::LightCyan));
|
block = block.border_style(Style::default().fg(Color::LightCyan));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user