Skip to content

Commit

Permalink
Merge branch 'feat/out_of_bounds' into dev, closes [#8]
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed May 30, 2022
2 parents 9c0e98a + 63b7de5 commit 4cf02e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/app_data/container_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl DockerControls {
match state {
State::Dead | State::Exited => vec![Self::Start, Self::Restart],
State::Paused => vec![Self::Unpause, Self::Stop],
State::Restarting => vec![Self::Stop],
State::Restarting => vec![Self::Stop],
State::Running => vec![Self::Pause, Self::Restart, Self::Stop],
_ => vec![],
}
Expand Down
6 changes: 4 additions & 2 deletions src/app_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@ impl AppData {
if self.containers.state.selected().is_some() {
self.containers.previous();
}
// docker rm -f $(docker ps -aq) will cause this to crash
self.containers.items.remove(index);
// Check is some, else can cause out of bounds error, if containers get removed before a docker update
if self.containers.items.get(index).is_some() {
self.containers.items.remove(index);
}
}
}

Expand Down
62 changes: 33 additions & 29 deletions src/ui/draw_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,36 +265,40 @@ pub fn draw_chart<B: Backend>(
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.split(area);
let (cpu, mem) = app_data.lock().containers.items[index].get_chart_data();

let cpu_dataset = vec![Dataset::default()
.marker(symbols::Marker::Dot)
.style(Style::default().fg(Color::Magenta))
.graph_type(GraphType::Line)
.data(&cpu.0)];

let mem_dataset = vec![Dataset::default()
.marker(symbols::Marker::Dot)
.style(Style::default().fg(Color::Cyan))
.graph_type(GraphType::Line)
.data(&mem.0)];
let cpu_chart = make_chart(
cpu.2,
String::from("cpu"),
cpu_dataset,
CpuStats::new(cpu.0.last().unwrap_or(&(0.00, 0.00)).1),
cpu.1,
);
let mem_chart = make_chart(
mem.2,
String::from("memory"),
mem_dataset,
ByteStats::new(mem.0.last().unwrap_or(&(0.0, 0.0)).1 as u64),
mem.1,
);

f.render_widget(cpu_chart, area[0]);
f.render_widget(mem_chart, area[1]);
// Check is some, else can cause out of bounds error, if containers get removed before a docker update
if let Some(data) = app_data.lock().containers.items.get(index) {
let (cpu, mem) = data.get_chart_data();

let cpu_dataset = vec![Dataset::default()
.marker(symbols::Marker::Dot)
.style(Style::default().fg(Color::Magenta))
.graph_type(GraphType::Line)
.data(&cpu.0)];

let mem_dataset = vec![Dataset::default()
.marker(symbols::Marker::Dot)
.style(Style::default().fg(Color::Cyan))
.graph_type(GraphType::Line)
.data(&mem.0)];
let cpu_chart = make_chart(
cpu.2,
String::from("cpu"),
cpu_dataset,
CpuStats::new(cpu.0.last().unwrap_or(&(0.00, 0.00)).1),
cpu.1,
);
let mem_chart = make_chart(
mem.2,
String::from("memory"),
mem_dataset,
ByteStats::new(mem.0.last().unwrap_or(&(0.0, 0.0)).1 as u64),
mem.1,
);

f.render_widget(cpu_chart, area[0]);
f.render_widget(mem_chart, area[1]);
}
}
}

Expand Down

0 comments on commit 4cf02e3

Please sign in to comment.