From ad190a144d54049297d34807baba0e5c3c903503 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Mon, 6 Jan 2020 23:07:58 -0500 Subject: Some basic cleaning --- src/app/data_collection/processes.rs | 16 +++++++++++++--- src/app/process_killer.rs | 3 +-- src/canvas.rs | 5 ++++- 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs index 16e612c1..a8916a8e 100644 --- a/src/app/data_collection/processes.rs +++ b/src/app/data_collection/processes.rs @@ -34,10 +34,20 @@ fn cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> error: path.push("stat"); let stat_results = std::fs::read_to_string(path)?; - let first_line = stat_results.split('\n').collect::>()[0]; + let first_line: &str; + + let split_results = stat_results.split('\n').collect::>(); + if split_results.is_empty() { + return Err(error::BottomError::InvalidIO { + message: format!( + "Unable to properly split the stat results; saw {} values, expected at least 1 value.", + split_results.len() + ), + }); + } else { + first_line = split_results[0]; + } - // TODO: Consider grabbing by number of threads instead, and summing the total? - // ie: 4 threads, so: (prev - cur) / cpu_0 + ... + (prev - cur) / cpu_n instead? This might be how top does it? let val = first_line.split_whitespace().collect::>(); // SC in case that the parsing will fail due to length: diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs index 1c4e5117..fe058bb9 100644 --- a/src/app/process_killer.rs +++ b/src/app/process_killer.rs @@ -47,9 +47,8 @@ pub fn kill_process_given_pid(pid: u32) -> crate::utils::error::Result<()> { message: "Sorry, macOS support is not implemented yet!".to_string(), }); } else { - // TODO: Others? return Err(BottomError::GenericError { - message: "Sorry, support operating systems outside the main three is not implemented yet!".to_string(), + message: "Sorry, support operating systems outside the main three are not implemented yet!".to_string(), }); } diff --git a/src/canvas.rs b/src/canvas.rs index 09f84438..26a9896c 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -373,6 +373,10 @@ fn draw_cpu_legend(f: &mut Frame, app_state: &mut app::A .render(f, draw_loc); } +fn _draw_memory_table(_f: &mut Frame, _app_state: &app::App, _draw_loc: Rect) { + todo!("Not implemented yet..."); // TODO: For basic mode +} + fn draw_memory_graph(f: &mut Frame, app_state: &app::App, draw_loc: Rect) { let mem_data: &[(f64, f64)] = &(app_state.canvas_data.mem_data); let swap_data: &[(f64, f64)] = &(app_state.canvas_data.swap_data); @@ -598,7 +602,6 @@ fn draw_disk_table(f: &mut Frame, app_state: &mut app::A ) }); - // TODO: We may have to dynamically remove some of these table elements based on size... Table::new(["Disk", "Mount", "Used", "Total", "Free", "R/s", "W/s"].iter(), disk_rows) .block( Block::default() -- cgit v1.2.3