diff --git a/README.md b/README.md index 488db01b..24b4adf4 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ A top clone, written in Rust. Inspired by both [gtop](https://github.com/aksakalli/gtop) and [gotop](https://github.com/cjbassi/gotop) +![Quick demo recording](assets/recording_1.gif) +*Note that the background you see is not part of the app, that's just because I use a slightly transparent background* + ## Installation ### Linux @@ -18,6 +21,32 @@ TODO: Test Currently, I'm unable to test on MacOS, so I'm not sure how well this will work, if at all. I'll try to source MacOS hardware to test this application. +## Usage + +### Keybinds (some may not be available on certain operating systems) + +#### General + +* ``q``, ``Esc``, or ``Ctrl-C`` to quit + +* ``Shift-Up/Shift-k``, ``Shift-Down/Shift-j``, ``Shift-Left/Shift-h``, ``Shift-Right/Shift-l`` to navigate between panels + +#### Processes Panel + +* ``dd`` to kill the selected process (currently only on Linux) - **I would highly recommend you to be careful using this, lest you accidentally kill the wrong process**. + +* ``c`` to sort by CPU usage. Sorts in descending order by default. Press again to reverse sorting order. + +* ``m`` to sort by memory usage. Sorts in descending order by default. Press again to reverse sorting order. + +* ``p`` to sort by PID. Sorts in ascending order by default. Press again to reverse sorting order. + +* ``n`` to sort by process name. Sorts in ascending order by default. Press again to reverse sorting order. + +### Mouse Actions + +* Scrolling either scrolls through the list if the panel is a table (Temperature, Disks, Processes), or zooms in and out if it is a chart + ## Thanks * As mentioned, this project is very much inspired by both [gotop](https://github.com/cjbassi/gotop) and [gtop](https://github.com/aksakalli/gtop) . diff --git a/TODO.md b/TODO.md index 63ab701e..bdfb3caf 100644 --- a/TODO.md +++ b/TODO.md @@ -16,7 +16,7 @@ * Keybindings -* Legend gets in the way at too small of a height... maybe modify tui a bit more to fix this. +~~* Legend gets in the way at too small of a height... maybe modify tui a bit more to fix this.~~ ## After making public @@ -52,4 +52,4 @@ * Modularity -* Potentially process managing? Depends on the libraries... +*~~Potentially process managing? Depends on the libraries...~~ Done on Linux! diff --git a/assets/recording_1.gif b/assets/recording_1.gif new file mode 100644 index 00000000..bb24987e Binary files /dev/null and b/assets/recording_1.gif differ diff --git a/src/app.rs b/src/app.rs index 15a48349..9331026c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -37,6 +37,7 @@ pub struct App { pub data : data_collection::Data, pub scroll_direction : ScrollDirection, pub previous_process_position : i64, + awaiting_d : bool, } impl App { @@ -57,12 +58,22 @@ impl App { data : data_collection::Data::default(), scroll_direction : ScrollDirection::DOWN, previous_process_position : 0, + awaiting_d : false, } } pub fn on_key(&mut self, c : char) { match c { 'q' => self.should_quit = true, + 'd' => { + if self.awaiting_d { + self.awaiting_d = false; + self.kill_highlighted_process().unwrap_or(()); // TODO: Should this be handled? + } + else { + self.awaiting_d = true; + } + } 'h' => self.on_right(), 'j' => self.on_down(), 'k' => self.on_up(), @@ -114,6 +125,16 @@ impl App { } _ => {} } + + if self.awaiting_d && c != 'd' { + self.awaiting_d = false; + } + } + + fn kill_highlighted_process(&self) -> crate::utils::error::Result<()> { + let current_pid = u64::from(self.data.list_of_processes[self.currently_selected_process_position as usize].pid); + process_killer::kill_process_given_pid(current_pid)?; + Ok(()) } pub fn on_left(&mut self) { diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs index a50d9595..ed0676a8 100644 --- a/src/app/data_collection.rs +++ b/src/app/data_collection.rs @@ -99,7 +99,7 @@ impl DataState { set_if_valid(&disks::get_disk_usage_list().await, &mut self.data.list_of_disks); push_if_valid(&disks::get_io_usage_list(false).await, &mut self.data.list_of_io); - //push_if_valid(&disks::get_io_usage_list(true).await, &mut self.data.list_of_physical_io); + //push_if_valid(&disks::get_io_usage_list(true).await, &mut self.data.list_of_physical_io); // Removed, seems irrelevant for now... set_if_valid(&temperature::get_temperature_data(&self.temperature_type).await, &mut self.data.list_of_temperature_sensor); if self.first_run { diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs index 8c89a458..e91034c4 100644 --- a/src/app/process_killer.rs +++ b/src/app/process_killer.rs @@ -2,7 +2,7 @@ use std::process::Command; /// Kills a process, given a PID. -pub fn kill_process_given_pid(pid : i64) -> crate::utils::error::Result<()> { +pub fn kill_process_given_pid(pid : u64) -> crate::utils::error::Result<()> { if cfg!(target_os = "linux") { // Linux Command::new("kill").arg(pid.to_string()).output()?;