diff --git a/README.md b/README.md index 5da2baea..4aeeecea 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ A gotop clone, written in Rust. Mostly done in an effort to learn Rust, while a * Definitely keybinds -* Filtering in processing +* Filtering in processes along with sorting * See if current disk activity is possible to do/graph? diff --git a/TOOD.md b/TOOD.md index cfd2dc2d..5ee6df57 100644 --- a/TOOD.md +++ b/TOOD.md @@ -8,8 +8,10 @@ * Write cursive display +* Charting? + * Keybindings * Theming -* Efficiency!!! Reuse hashmaps for example. +* Efficiency!!! Make sure no wasted hashmaps, use references, etc. diff --git a/src/main.rs b/src/main.rs index 647d585d..bae91631 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,29 @@ mod widgets; use widgets::{cpu, disks, mem, network, processes, temperature}; fn main() { + // Initialize let mut system = System::new(); - system.refresh_all(); - //processes::draw_sorted_processes(processes::ProcessSorting::NAME, true, &system); - disks::draw_disk_usage_data(&system); + let refresh_interval = 10; + + // Start loop (TODO: do that) + loop { + system.refresh_system(); + system.refresh_processes(); + system.refresh_disk_list(); + system.refresh_disks(); + system.refresh_network(); + + // Get data, potentially store? + //let list_of_processes = processes::get_sorted_processes_list(processes::ProcessSorting::NAME, true, &system); + let list_of_disks = disks::get_disk_usage_list(&system); + + for disk in list_of_disks { + println!("{} is mounted on {}: {}/{}", disk.name, disk.mount_point, disk.avail_space, disk.total_space); + } + + // Draw using cursive + + // Repeat on interval + std::thread::sleep(std::time::Duration::from_secs(refresh_interval)); + } } diff --git a/src/widgets/cpu.rs b/src/widgets/cpu.rs index aad8bd36..60e89e69 100644 --- a/src/widgets/cpu.rs +++ b/src/widgets/cpu.rs @@ -1,3 +1,9 @@ +struct TimedCPUData<'a> { + cpu_name: &'a str, + cpu_usage: f32, + time: std::time::Duration, +} + fn get_timestamped_cpu_data() {} -fn draw_cpu_data() {} +pub fn get_cpu_data_list() {} diff --git a/src/widgets/disks.rs b/src/widgets/disks.rs index 50da2f03..9ce4ab46 100644 --- a/src/widgets/disks.rs +++ b/src/widgets/disks.rs @@ -1,11 +1,24 @@ -use sysinfo::{System, SystemExt, DiskExt}; +use sysinfo::{System, SystemExt, Disk, DiskExt}; -fn get_timestamped_disk_data() {} - -pub fn draw_disk_usage_data(sys: &System) { - let list_of_disks = sys.get_disks(); - - for disk in list_of_disks { - println!("Disk: Total size: {}, used: {}, disk: {}, mount: {}", disk.get_total_space(), disk.get_total_space() - disk.get_available_space(), disk.get_name().to_str().unwrap(), disk.get_mount_point().to_str().unwrap()); - } +pub struct DiskInfo<'a> { + pub name: &'a str, + pub mount_point: &'a str, + pub avail_space: u64, + pub total_space: u64, +} + +pub fn get_disk_usage_list(sys: &System) -> Vec { + let result_disks = sys.get_disks(); + let mut vec_disks : Vec = Vec::new(); + + for disk in result_disks { + vec_disks.push(DiskInfo { + name: disk.get_name().to_str().unwrap(), + mount_point: disk.get_mount_point().to_str().unwrap(), + avail_space: disk.get_available_space(), + total_space: disk.get_total_space(), + }); + } + + vec_disks } diff --git a/src/widgets/mem.rs b/src/widgets/mem.rs index ebd48893..6bb900aa 100644 --- a/src/widgets/mem.rs +++ b/src/widgets/mem.rs @@ -1,3 +1,3 @@ fn get_timestamped_ram_data() {} -fn draw_ram_data() {} \ No newline at end of file +pub fn get_ram_data_list() {} diff --git a/src/widgets/network.rs b/src/widgets/network.rs index 7353da03..1f35ca7f 100644 --- a/src/widgets/network.rs +++ b/src/widgets/network.rs @@ -1,3 +1,3 @@ fn get_timestamped_network_data() {} -fn draw_network_data() {} \ No newline at end of file +fn get_network_data_list() {} diff --git a/src/widgets/processes.rs b/src/widgets/processes.rs index 072b14c8..4d38fc03 100644 --- a/src/widgets/processes.rs +++ b/src/widgets/processes.rs @@ -50,7 +50,7 @@ fn get_ordering(a_val: T, b_val: T, reverse_order: bool } } -pub fn draw_sorted_processes(sorting_method: ProcessSorting, reverse_order: bool, sys: &System) { +pub fn get_sorted_processes_list(sorting_method: ProcessSorting, reverse_order: bool, sys: &System) { let process_hashmap = sys.get_process_list(); // TODO: Evaluate whether this is too slow! diff --git a/src/widgets/temperature.rs b/src/widgets/temperature.rs index 066be228..2617bab9 100644 --- a/src/widgets/temperature.rs +++ b/src/widgets/temperature.rs @@ -1,3 +1,3 @@ fn get_timestamped_temperature() {} -fn draw_temperatures() {} \ No newline at end of file +fn get_temps_list() {} diff --git a/src/window/mod.rs b/src/window/mod.rs new file mode 100644 index 00000000..e04802fd --- /dev/null +++ b/src/window/mod.rs @@ -0,0 +1 @@ +use cursive::Cursive; \ No newline at end of file