refactors: unwraps() removed, and/or map_or() used
This commit is contained in:
+22
-13
@@ -313,9 +313,7 @@ impl AppData {
|
|||||||
/// So can display nicely and evenly
|
/// So can display nicely and evenly
|
||||||
pub fn get_width(&self) -> Columns {
|
pub fn get_width(&self) -> Columns {
|
||||||
let mut output = Columns::new();
|
let mut output = Columns::new();
|
||||||
// Think this is causing issues
|
|
||||||
let count = |x: &String| x.chars().count();
|
let count = |x: &String| x.chars().count();
|
||||||
// let count = |_:&String|10;
|
|
||||||
|
|
||||||
for container in &self.containers.items {
|
for container in &self.containers.items {
|
||||||
let cpu_count = count(
|
let cpu_count = count(
|
||||||
@@ -412,7 +410,7 @@ impl AppData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Update, or insert, containers
|
/// Update, or insert, containers
|
||||||
pub fn update_containers(&mut self, containers: &[ContainerSummary]) {
|
pub fn update_containers(&mut self, containers: &mut [ContainerSummary]) {
|
||||||
let all_ids = self.get_all_ids();
|
let all_ids = self.get_all_ids();
|
||||||
|
|
||||||
if !containers.is_empty() && self.containers.state.selected().is_none() {
|
if !containers.is_empty() && self.containers.state.selected().is_none() {
|
||||||
@@ -437,19 +435,28 @@ impl AppData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in containers.iter() {
|
for i in containers.iter_mut() {
|
||||||
if let Some(id) = i.id.as_ref() {
|
if let Some(id) = i.id.as_ref() {
|
||||||
// maybe if no name then continue?
|
// maybe if no name then continue?
|
||||||
let name = i.names.as_ref().map_or("".to_owned(), |f|f.get(0).map_or("".to_owned(), |f|{
|
let name = i.names.as_mut().map_or("".to_owned(), |n| {
|
||||||
let mut n = f.clone();
|
n.get_mut(0).map_or("".to_owned(), |f| {
|
||||||
if n.starts_with('/') {
|
if f.starts_with('/') {
|
||||||
n.remove(0);
|
f.remove(0);
|
||||||
}
|
}
|
||||||
n
|
f.to_string()
|
||||||
}));
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
let state = State::from(
|
||||||
|
i.state
|
||||||
|
.as_ref()
|
||||||
|
.map_or("dead".to_owned(), |f| f.trim().to_owned()),
|
||||||
|
);
|
||||||
|
let status = i
|
||||||
|
.status
|
||||||
|
.as_ref()
|
||||||
|
.map_or("".to_owned(), |f| f.trim().to_owned());
|
||||||
|
|
||||||
let state = State::from(i.state.as_ref().map_or("dead".to_owned(), |f|f.trim().to_owned()));
|
|
||||||
let status = i.status.as_ref().map_or("".to_owned(), |f| f.trim().to_owned());
|
|
||||||
let image = i.image.as_ref().map_or("".to_owned(), |f| f.clone());
|
let image = i.image.as_ref().map_or("".to_owned(), |f| f.clone());
|
||||||
|
|
||||||
if let Some(current_container) = self.get_container_by_id(id) {
|
if let Some(current_container) = self.get_container_by_id(id) {
|
||||||
@@ -472,10 +479,12 @@ impl AppData {
|
|||||||
current_container.state = state;
|
current_container.state = state;
|
||||||
};
|
};
|
||||||
if current_container.image != image {
|
if current_container.image != image {
|
||||||
|
// limit image name to 64 chars?
|
||||||
// current_container.image = image.chars().into_iter().take(64).collect();
|
// current_container.image = image.chars().into_iter().take(64).collect();
|
||||||
current_container.image = image;
|
current_container.image = image;
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
// limit image name to 64 chars?
|
||||||
// let mut container = ContainerItem::new(id.clone(), status, image.chars().into_iter().take(64).collect(), state, name);
|
// let mut container = ContainerItem::new(id.clone(), status, image.chars().into_iter().take(64).collect(), state, name);
|
||||||
let mut container = ContainerItem::new(id.clone(), status, image, state, name);
|
let mut container = ContainerItem::new(id.clone(), status, image, state, name);
|
||||||
container.logs.end();
|
container.logs.end();
|
||||||
@@ -507,7 +516,7 @@ impl AppData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if container.logs.state.selected().is_none()
|
if container.logs.state.selected().is_none()
|
||||||
|| container.logs.state.selected().unwrap_or_default() + 1 == current_len
|
|| container.logs.state.selected().map_or(1, |f| f + 1) == current_len
|
||||||
{
|
{
|
||||||
container.logs.end();
|
container.logs.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,5 @@ impl fmt::Display for AppError {
|
|||||||
write!(f, "Unbale to {}able mouse capture", reason)
|
write!(f, "Unbale to {}able mouse capture", reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,8 +279,8 @@ pub fn chart<B: Backend>(
|
|||||||
.style(Style::default().fg(Color::Cyan))
|
.style(Style::default().fg(Color::Cyan))
|
||||||
.graph_type(GraphType::Line)
|
.graph_type(GraphType::Line)
|
||||||
.data(&mem.0)];
|
.data(&mem.0)];
|
||||||
let cpu_stats = CpuStats::new(cpu.0.last().unwrap_or(&(0.00, 0.00)).1);
|
let cpu_stats = CpuStats::new(cpu.0.last().map_or(0.00, |f| f.1));
|
||||||
let mem_stats = ByteStats::new(mem.0.last().unwrap_or(&(0.0, 0.0)).1 as u64);
|
let mem_stats = ByteStats::new(mem.0.last().map_or(0, |f| f.1 as u64));
|
||||||
let cpu_chart = make_chart(&cpu.2, "cpu", cpu_dataset, &cpu_stats, &cpu.1);
|
let cpu_chart = make_chart(&cpu.2, "cpu", cpu_dataset, &cpu_stats, &cpu.1);
|
||||||
let mem_chart = make_chart(&mem.2, "memory", mem_dataset, &mem_stats, &mem.1);
|
let mem_chart = make_chart(&mem.2, "memory", mem_dataset, &mem_stats, &mem.1);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -63,7 +63,7 @@ pub async fn create_ui(
|
|||||||
LeaveAlternateScreen,
|
LeaveAlternateScreen,
|
||||||
DisableMouseCapture
|
DisableMouseCapture
|
||||||
)?;
|
)?;
|
||||||
terminal.show_cursor().unwrap_or(());
|
terminal.show_cursor()?;
|
||||||
|
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
println!("{}", err);
|
println!("{}", err);
|
||||||
|
|||||||
Reference in New Issue
Block a user