Fixed problem with invalid vector index access.

This commit is contained in:
Clement Tsang 2019-12-13 02:42:36 -05:00
parent a6b746896b
commit 12b4518fa1
5 changed files with 22 additions and 25 deletions

View file

@ -26,16 +26,10 @@ heim = "0.0.8"
log = "0.4"
rayon = "1.2"
regex = "1.3.1"
sysinfo = "0.10"
sysinfo = "0.9"
tokio = "0.2.4"
winapi = "0.3.8"
[dependencies.tui]
# git = "https://github.com/ClementTsang/tui-rs"
# path = "../tui-rs"
version = "0.7"
default-features = false
features = ['crossterm']
tui = {version = "0.7", features = ["crossterm"], default-features = false }
[dev-dependencies]
assert_cmd = "0.10"

View file

@ -72,6 +72,10 @@ impl DataState {
pub fn init(&mut self) {
self.sys.refresh_system();
self.sys.refresh_network();
if !cfg!(target_os = "linux") {
// For now, might be just windows tbh
self.sys.refresh_processes();
}
}
pub async fn update_data(&mut self) {

View file

@ -104,19 +104,19 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
.split(vertical_chunks[2]);
// Component specific chunks
let cpu_chunk = Layout::default()
let _cpu_chunk = Layout::default()
.direction(Direction::Horizontal)
.margin(0)
.constraints([Constraint::Percentage(90), Constraint::Percentage(10)].as_ref())
.split(vertical_chunks[0]);
let mem_chunk = Layout::default()
let _mem_chunk = Layout::default()
.direction(Direction::Horizontal)
.margin(0)
.constraints([Constraint::Percentage(90), Constraint::Percentage(10)].as_ref())
.split(middle_chunks[0]);
let network_chunk = Layout::default()
let _network_chunk = Layout::default()
.direction(Direction::Horizontal)
.margin(0)
.constraints([Constraint::Percentage(90), Constraint::Percentage(10)].as_ref())
@ -156,12 +156,13 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
}
if !canvas_data.cpu_data.is_empty() && app_state.show_average_cpu {
// Unwrap should be safe here, this assumes that the cpu_data vector is populated...
dataset_vector.push(
Dataset::default()
.name(&canvas_data.cpu_data[0].0)
.name(&canvas_data.cpu_data.first().unwrap().0)
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
.style(Style::default().fg(COLOUR_LIST[canvas_data.cpu_data.len() - 1 % COLOUR_LIST.len()]))
.data(&(canvas_data.cpu_data[0].1)),
.data(&(canvas_data.cpu_data.first().unwrap().1)),
);
}
@ -195,8 +196,8 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
+ &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))
+ &format!(
" {:.1}GB/{:.1}GB",
canvas_data.mem_values[0].0 as f64 / 1024.0,
canvas_data.mem_values[0].1 as f64 / 1024.0
canvas_data.mem_values.first().unwrap_or(&(0, 0)).0 as f64 / 1024.0,
canvas_data.mem_values.first().unwrap_or(&(0, 0)).1 as f64 / 1024.0
);
let swap_name: String;

View file

@ -24,11 +24,11 @@ mod utils {
}
mod canvas;
mod constants;
mod convert_data;
mod data_conversion;
use app::data_collection;
use constants::TICK_RATE_IN_MILLISECONDS;
use convert_data::*;
use data_conversion::*;
use utils::error::{self, RustopError};
// End imports
@ -175,17 +175,15 @@ fn main() -> error::Result<()> {
}
// Event loop
let mut data_state = data_collection::DataState::default();
data_state.init();
data_state.set_temperature_type(app.temperature_type.clone());
let (rtx, rrx) = mpsc::channel();
{
let tx = tx.clone();
let temp_type = app.temperature_type.clone();
let mut first_run = true;
thread::spawn(move || {
let tx = tx.clone();
let mut data_state = data_collection::DataState::default();
data_state.init();
data_state.set_temperature_type(temp_type);
loop {
if let Ok(message) = rrx.try_recv() {
match message {
@ -282,19 +280,19 @@ fn main() -> error::Result<()> {
canvas_data.swap_data = update_swap_data_points(&app.data);
canvas_data.cpu_data = update_cpu_data_points(app.show_average_cpu, &app.data);
debug!("Update event complete.");
//debug!("Update event complete.");
}
}
}
}
// Draw!
if let Err(err) = canvas::draw_data(&mut terminal, &mut app, &canvas_data) {
input().disable_mouse_mode().unwrap();
input().disable_mouse_mode()?;
error!("{}", err);
return Err(err);
}
}
input().disable_mouse_mode().unwrap();
input().disable_mouse_mode()?;
Ok(())
}