2019-09-12 00:41:11 +00:00
|
|
|
pub mod data_collection;
|
2019-09-14 21:07:18 +00:00
|
|
|
use data_collection::{processes, temperature};
|
2019-09-08 23:56:23 +00:00
|
|
|
|
2019-09-16 23:05:44 +00:00
|
|
|
mod process_killer;
|
|
|
|
|
2019-09-15 18:16:18 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
// Probably only use the list elements...
|
|
|
|
pub enum ApplicationPosition {
|
|
|
|
CPU,
|
|
|
|
MEM,
|
|
|
|
DISK,
|
|
|
|
TEMP,
|
|
|
|
NETWORK,
|
|
|
|
PROCESS,
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:18:42 +00:00
|
|
|
pub enum ScrollDirection {
|
|
|
|
/// UP means scrolling up --- this usually DECREMENTS
|
|
|
|
UP,
|
|
|
|
/// DOWN means scrolling down --- this usually INCREMENTS
|
|
|
|
DOWN,
|
|
|
|
}
|
|
|
|
|
2019-09-14 20:46:14 +00:00
|
|
|
pub struct App {
|
2019-09-08 23:56:23 +00:00
|
|
|
pub should_quit : bool,
|
2019-09-09 22:34:13 +00:00
|
|
|
pub process_sorting_type : processes::ProcessSorting,
|
|
|
|
pub process_sorting_reverse : bool,
|
|
|
|
pub to_be_resorted : bool,
|
2019-09-16 20:18:42 +00:00
|
|
|
pub currently_selected_process_position : i64,
|
|
|
|
pub currently_selected_disk_position : i64,
|
|
|
|
pub currently_selected_temperature_position : i64,
|
2019-09-14 21:07:18 +00:00
|
|
|
pub temperature_type : temperature::TemperatureType,
|
2019-09-14 20:46:14 +00:00
|
|
|
pub update_rate_in_milliseconds : u64,
|
2019-09-14 21:07:18 +00:00
|
|
|
pub show_average_cpu : bool,
|
2019-09-15 18:16:18 +00:00
|
|
|
pub current_application_position : ApplicationPosition,
|
|
|
|
pub current_zoom_level_percent : f64, // Make at most 200, least 50?
|
2019-09-16 20:18:42 +00:00
|
|
|
pub data : data_collection::Data,
|
|
|
|
pub scroll_direction : ScrollDirection,
|
|
|
|
pub previous_process_position : i64,
|
2019-09-17 01:45:48 +00:00
|
|
|
awaiting_d : bool,
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|
|
|
|
|
2019-09-14 20:46:14 +00:00
|
|
|
impl App {
|
2019-09-14 21:07:18 +00:00
|
|
|
pub fn new(show_average_cpu : bool, temperature_type : temperature::TemperatureType, update_rate_in_milliseconds : u64) -> App {
|
2019-09-09 04:09:58 +00:00
|
|
|
App {
|
2019-09-14 21:07:18 +00:00
|
|
|
process_sorting_type : processes::ProcessSorting::CPU,
|
2019-09-09 04:09:58 +00:00
|
|
|
should_quit : false,
|
2019-09-10 22:22:34 +00:00
|
|
|
process_sorting_reverse : true,
|
2019-09-09 22:34:13 +00:00
|
|
|
to_be_resorted : false,
|
2019-09-15 18:16:18 +00:00
|
|
|
currently_selected_process_position : 0,
|
|
|
|
currently_selected_disk_position : 0,
|
|
|
|
currently_selected_temperature_position : 0,
|
2019-09-14 20:46:14 +00:00
|
|
|
temperature_type,
|
|
|
|
update_rate_in_milliseconds,
|
2019-09-14 21:07:18 +00:00
|
|
|
show_average_cpu,
|
2019-09-15 18:16:18 +00:00
|
|
|
current_application_position : ApplicationPosition::PROCESS,
|
|
|
|
current_zoom_level_percent : 100.0,
|
2019-09-16 20:18:42 +00:00
|
|
|
data : data_collection::Data::default(),
|
|
|
|
scroll_direction : ScrollDirection::DOWN,
|
|
|
|
previous_process_position : 0,
|
2019-09-17 01:45:48 +00:00
|
|
|
awaiting_d : false,
|
2019-09-09 04:09:58 +00:00
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn on_key(&mut self, c : char) {
|
|
|
|
match c {
|
|
|
|
'q' => self.should_quit = true,
|
2019-09-17 01:45:48 +00:00
|
|
|
'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;
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 22:22:34 +00:00
|
|
|
'h' => self.on_right(),
|
|
|
|
'j' => self.on_down(),
|
|
|
|
'k' => self.on_up(),
|
|
|
|
'l' => self.on_left(),
|
2019-09-09 04:09:58 +00:00
|
|
|
'c' => {
|
2019-09-15 01:48:29 +00:00
|
|
|
// TODO: This should depend on what tile you're on!
|
2019-09-10 22:22:34 +00:00
|
|
|
match self.process_sorting_type {
|
|
|
|
processes::ProcessSorting::CPU => self.process_sorting_reverse = !self.process_sorting_reverse,
|
|
|
|
_ => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::CPU;
|
|
|
|
self.process_sorting_reverse = true;
|
|
|
|
}
|
|
|
|
}
|
2019-09-09 22:34:13 +00:00
|
|
|
self.to_be_resorted = true;
|
2019-09-16 20:18:42 +00:00
|
|
|
self.currently_selected_process_position = 0;
|
2019-09-09 04:09:58 +00:00
|
|
|
}
|
|
|
|
'm' => {
|
2019-09-10 22:22:34 +00:00
|
|
|
match self.process_sorting_type {
|
|
|
|
processes::ProcessSorting::MEM => self.process_sorting_reverse = !self.process_sorting_reverse,
|
|
|
|
_ => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::MEM;
|
|
|
|
self.process_sorting_reverse = true;
|
|
|
|
}
|
|
|
|
}
|
2019-09-09 22:34:13 +00:00
|
|
|
self.to_be_resorted = true;
|
2019-09-16 20:18:42 +00:00
|
|
|
self.currently_selected_process_position = 0;
|
2019-09-09 04:09:58 +00:00
|
|
|
}
|
|
|
|
'p' => {
|
2019-09-10 22:22:34 +00:00
|
|
|
match self.process_sorting_type {
|
|
|
|
processes::ProcessSorting::PID => self.process_sorting_reverse = !self.process_sorting_reverse,
|
|
|
|
_ => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::PID;
|
|
|
|
self.process_sorting_reverse = false;
|
|
|
|
}
|
|
|
|
}
|
2019-09-09 22:34:13 +00:00
|
|
|
self.to_be_resorted = true;
|
2019-09-16 20:18:42 +00:00
|
|
|
self.currently_selected_process_position = 0;
|
2019-09-09 04:09:58 +00:00
|
|
|
}
|
|
|
|
'n' => {
|
2019-09-10 22:22:34 +00:00
|
|
|
match self.process_sorting_type {
|
|
|
|
processes::ProcessSorting::NAME => self.process_sorting_reverse = !self.process_sorting_reverse,
|
|
|
|
_ => {
|
|
|
|
self.process_sorting_type = processes::ProcessSorting::NAME;
|
|
|
|
self.process_sorting_reverse = false;
|
|
|
|
}
|
|
|
|
}
|
2019-09-09 22:34:13 +00:00
|
|
|
self.to_be_resorted = true;
|
2019-09-16 20:18:42 +00:00
|
|
|
self.currently_selected_process_position = 0;
|
2019-09-09 04:09:58 +00:00
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
2019-09-17 01:45:48 +00:00
|
|
|
|
|
|
|
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(())
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 22:34:13 +00:00
|
|
|
pub fn on_left(&mut self) {
|
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
|
2019-09-09 22:34:13 +00:00
|
|
|
pub fn on_right(&mut self) {
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn on_up(&mut self) {
|
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
|
2019-09-09 22:34:13 +00:00
|
|
|
pub fn on_down(&mut self) {
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|
2019-09-15 18:16:18 +00:00
|
|
|
|
|
|
|
pub fn decrement_position_count(&mut self) {
|
|
|
|
match self.current_application_position {
|
2019-09-16 20:18:42 +00:00
|
|
|
ApplicationPosition::PROCESS => self.change_process_position(-1),
|
|
|
|
ApplicationPosition::TEMP => self.change_temp_position(-1),
|
|
|
|
ApplicationPosition::DISK => self.change_disk_position(-1),
|
2019-09-15 18:16:18 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
2019-09-16 20:18:42 +00:00
|
|
|
self.scroll_direction = ScrollDirection::UP;
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn increment_position_count(&mut self) {
|
|
|
|
match self.current_application_position {
|
2019-09-16 20:18:42 +00:00
|
|
|
ApplicationPosition::PROCESS => self.change_process_position(1),
|
|
|
|
ApplicationPosition::TEMP => self.change_temp_position(1),
|
|
|
|
ApplicationPosition::DISK => self.change_disk_position(1),
|
2019-09-15 18:16:18 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
2019-09-16 20:18:42 +00:00
|
|
|
self.scroll_direction = ScrollDirection::DOWN;
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:18:42 +00:00
|
|
|
fn change_process_position(&mut self, num_to_change_by : i64) {
|
|
|
|
if self.currently_selected_process_position + num_to_change_by >= 0
|
|
|
|
&& self.currently_selected_process_position + num_to_change_by < self.data.list_of_processes.len() as i64
|
|
|
|
{
|
|
|
|
self.currently_selected_process_position += num_to_change_by;
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:18:42 +00:00
|
|
|
fn change_temp_position(&mut self, num_to_change_by : i64) {
|
|
|
|
if self.currently_selected_temperature_position + num_to_change_by >= 0 {
|
|
|
|
self.currently_selected_temperature_position += num_to_change_by;
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
// else if self.currently_selected_temperature_position < // TODO: Need to finish this! This should never go PAST the number of elements
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:18:42 +00:00
|
|
|
fn change_disk_position(&mut self, num_to_change_by : i64) {
|
|
|
|
if self.currently_selected_disk_position + num_to_change_by >= 0 {
|
|
|
|
self.currently_selected_disk_position += num_to_change_by;
|
2019-09-15 18:16:18 +00:00
|
|
|
}
|
|
|
|
// else if self.currently_selected_disk_position < // TODO: Need to finish this! This should never go PAST the number of elements
|
|
|
|
}
|
2019-09-08 23:56:23 +00:00
|
|
|
}
|