diff --git a/TODO.md b/TODO.md index 3f0dff70..7399ca69 100644 --- a/TODO.md +++ b/TODO.md @@ -12,12 +12,14 @@ * ~~FIX PROCESSES AHHHHHH~~ -* Scrolling in at least processes +~~* Scrolling in at least processes~~ * Keybindings ## After making public +* Tests + * Mouse + key events conflict? Make it so that some events don't clog up the loop if they are not valid keys! * Header should be clear on current sorting direction! @@ -28,7 +30,7 @@ * ~~Add custom error because it's really messy~~ Done, but need to implement across rest of app! -* Remove any ``unwrap()``, ensure no crashing! +* Remove any ``unwrap()``, ensure no crashing! Might have to use this: * Scrolling event in lists diff --git a/src/app.rs b/src/app.rs index 0b1dc2e7..15a48349 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,8 @@ pub mod data_collection; use data_collection::{processes, temperature}; +mod process_killer; + #[allow(dead_code)] // Probably only use the list elements... pub enum ApplicationPosition { diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs index c292fb94..a50d9595 100644 --- a/src/app/data_collection.rs +++ b/src/app/data_collection.rs @@ -10,13 +10,13 @@ pub mod network; pub mod processes; pub mod temperature; -fn set_if_valid(result : &Result, value_to_set : &mut T) { +fn set_if_valid(result : &Result, value_to_set : &mut T) { if let Ok(result) = result { *value_to_set = (*result).clone(); } } -fn push_if_valid(result : &Result, vector_to_push : &mut Vec) { +fn push_if_valid(result : &Result, vector_to_push : &mut Vec) { if let Ok(result) = result { vector_to_push.push(result.clone()); } diff --git a/src/app/data_collection/cpu.rs b/src/app/data_collection/cpu.rs index 8a09ee17..0a44bac8 100644 --- a/src/app/data_collection/cpu.rs +++ b/src/app/data_collection/cpu.rs @@ -13,7 +13,7 @@ pub struct CPUPackage { pub instant : Instant, } -pub fn get_cpu_data_list(sys : &System) -> Result { +pub fn get_cpu_data_list(sys : &System) -> crate::utils::error::Result { let cpu_data = sys.get_processor_list(); let mut cpu_vec = Vec::new(); diff --git a/src/app/data_collection/disks.rs b/src/app/data_collection/disks.rs index 10349a61..1d444bf6 100644 --- a/src/app/data_collection/disks.rs +++ b/src/app/data_collection/disks.rs @@ -23,8 +23,7 @@ pub struct IOPackage { pub instant : Instant, } -// TODO: This is total --- we have to change the calculation to PER SECOND! -pub async fn get_io_usage_list(get_physical : bool) -> Result { +pub async fn get_io_usage_list(get_physical : bool) -> crate::utils::error::Result { let mut io_hash : std::collections::HashMap = std::collections::HashMap::new(); if get_physical { let mut physical_counter_stream = heim::disk::io_counters_physical(); @@ -63,7 +62,7 @@ pub async fn get_io_usage_list(get_physical : bool) -> Result Result, heim::Error> { +pub async fn get_disk_usage_list() -> crate::utils::error::Result> { let mut vec_disks : Vec = Vec::new(); let mut partitions_stream = heim::disk::partitions_physical(); diff --git a/src/app/data_collection/mem.rs b/src/app/data_collection/mem.rs index c7c06f8d..929ee326 100644 --- a/src/app/data_collection/mem.rs +++ b/src/app/data_collection/mem.rs @@ -8,7 +8,7 @@ pub struct MemData { pub instant : Instant, } -pub async fn get_mem_data_list() -> Result { +pub async fn get_mem_data_list() -> crate::utils::error::Result { let memory = heim::memory::memory().await?; Ok(MemData { @@ -18,7 +18,7 @@ pub async fn get_mem_data_list() -> Result { }) } -pub async fn get_swap_data_list() -> Result { +pub async fn get_swap_data_list() -> crate::utils::error::Result { let memory = heim::memory::swap().await?; Ok(MemData { diff --git a/src/app/data_collection/network.rs b/src/app/data_collection/network.rs index d8cad3ff..22e39615 100644 --- a/src/app/data_collection/network.rs +++ b/src/app/data_collection/network.rs @@ -11,7 +11,7 @@ pub struct NetworkData { pub instant : Instant, } -pub fn get_network_data(sys : &System) -> Result { +pub fn get_network_data(sys : &System) -> crate::utils::error::Result { let network_data = sys.get_network(); Ok(NetworkData { rx : network_data.get_income(), diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs index cb9d4516..65b47d12 100644 --- a/src/app/data_collection/processes.rs +++ b/src/app/data_collection/processes.rs @@ -171,16 +171,13 @@ fn convert_ps(process : &str, cpu_usage_percentage : f64, prev_pid_stats : &mut pub async fn get_sorted_processes_list( prev_idle : &mut f64, prev_non_idle : &mut f64, prev_pid_stats : &mut std::collections::HashMap, -) -> Result, heim::Error> { +) -> crate::utils::error::Result> { let mut process_vector : Vec = Vec::new(); if cfg!(target_os = "linux") { // Linux specific - this is a massive pain... ugh. - let ps_result = Command::new("ps") - .args(&["-axo", "pid:10,comm:50,%mem:5", "--noheader"]) - .output() - .expect("Failed to execute."); + let ps_result = Command::new("ps").args(&["-axo", "pid:10,comm:50,%mem:5", "--noheader"]).output()?; let ps_stdout = String::from_utf8_lossy(&ps_result.stdout); let split_string = ps_stdout.split('\n'); let cpu_usage = vangelis_cpu_usage_calculation(prev_idle, prev_non_idle).unwrap(); // TODO: FIX THIS ERROR CHECKING diff --git a/src/app/data_collection/temperature.rs b/src/app/data_collection/temperature.rs index 60f0a25d..f650592e 100644 --- a/src/app/data_collection/temperature.rs +++ b/src/app/data_collection/temperature.rs @@ -19,7 +19,7 @@ impl Default for TemperatureType { } } -pub async fn get_temperature_data(temp_type : &TemperatureType) -> Result, heim::Error> { +pub async fn get_temperature_data(temp_type : &TemperatureType) -> crate::utils::error::Result> { let mut temperature_vec : Vec = Vec::new(); let mut sensor_data = heim::sensors::temperatures(); diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs new file mode 100644 index 00000000..8c89a458 --- /dev/null +++ b/src/app/process_killer.rs @@ -0,0 +1,24 @@ +/// This file is meant to house (OS specific) implementations on how to kill processes. +use std::process::Command; + +/// Kills a process, given a PID. +pub fn kill_process_given_pid(pid : i64) -> crate::utils::error::Result<()> { + if cfg!(target_os = "linux") { + // Linux + Command::new("kill").arg(pid.to_string()).output()?; + } + else if cfg!(target_os = "windows") { + // Windows + debug!("Sorry, Windows support is not implemented yet!"); + } + else if cfg!(target_os = "macos") { + // TODO: macOS + debug!("Sorry, macOS support is not implemented yet!"); + } + else { + // TODO: Others? + debug!("Sorry, other support this is not implemented yet!"); + } + + Ok(()) +} diff --git a/src/canvas.rs b/src/canvas.rs index 91544e96..10384472 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -226,10 +226,10 @@ pub fn draw_data(terminal : &mut Terminal, app_sta } }; - debug!( + /*debug!( "START POSN: {}, PREV POSN: {}, CURRENT SELECTED POSN: {}, NUM ROWS: {}", start_position, app_state.previous_process_position, app_state.currently_selected_process_position, num_rows - ); + );*/ let sliced_vec : Vec> = (&canvas_data.process_data[start_position as usize..]).to_vec();