summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml8
-rw-r--r--rustfmt.toml1
-rw-r--r--src/app.rs88
-rw-r--r--src/app/data_collection.rs62
-rw-r--r--src/app/data_collection/cpu.rs16
-rw-r--r--src/app/data_collection/mem.rs18
-rw-r--r--src/app/data_collection/processes.rs103
-rw-r--r--src/app/process_killer.rs13
-rw-r--r--src/canvas.rs87
-rw-r--r--src/constants.rs8
-rw-r--r--src/convert_data.rs121
-rw-r--r--src/main.rs33
-rw-r--r--src/utils/logging.rs12
13 files changed, 257 insertions, 313 deletions
diff --git a/Cargo.toml b/Cargo.toml
index e2f90ce5..9c1a4bbe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,7 +17,7 @@ path = "src/main.rs"
[dependencies]
chrono = "0.4.9"
clap = "2.33.0"
-crossterm = "^0.10"
+crossterm = "0.13"
failure = "0.1.5"
futures-preview = "0.3.0-alpha.18"
fern = "0.5"
@@ -32,10 +32,8 @@ sysinfo = "0.9.4"
tokio = "0.2.0-alpha.4"
winapi = "0.3.8"
-[dependencies.tui-temp-fork]
-#git = "https://github.com/ClementTsang/tui-rs"
-path = "../tui-rs"
-version = "0.6"
+[dependencies.tui]
+version = "0.7"
default-features = false
features = ['crossterm']
diff --git a/rustfmt.toml b/rustfmt.toml
index 4bc25f6e..7aa76c5c 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,4 +1,5 @@
max_width = 150
+newline_style = "Unix"
reorder_imports = true
control_brace_style = "ClosingNextLine"
fn_args_layout = "Compressed"
diff --git a/src/app.rs b/src/app.rs
index 752b0be9..59f376a3 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -21,56 +21,55 @@ pub enum ScrollDirection {
}
pub struct App {
- pub process_sorting_type : processes::ProcessSorting,
- pub process_sorting_reverse : bool,
- pub to_be_resorted : bool,
- pub currently_selected_process_position : i64,
- pub currently_selected_disk_position : i64,
- pub currently_selected_temperature_position : i64,
- pub temperature_type : temperature::TemperatureType,
- pub update_rate_in_milliseconds : u64,
- pub show_average_cpu : bool,
- pub current_application_position : ApplicationPosition,
- pub current_zoom_level_percent : f64, // Make at most 200, least 50?
- pub data : data_collection::Data,
- pub scroll_direction : ScrollDirection,
- pub previous_disk_position : i64,
- pub previous_temp_position : i64,
- pub previous_process_position : i64,
- awaiting_second_d : bool,
- pub use_dot : bool,
- pub show_help : bool,
- pub is_frozen : bool,
+ pub process_sorting_type: processes::ProcessSorting,
+ pub process_sorting_reverse: bool,
+ pub to_be_resorted: bool,
+ pub currently_selected_process_position: i64,
+ pub currently_selected_disk_position: i64,
+ pub currently_selected_temperature_position: i64,
+ pub temperature_type: temperature::TemperatureType,
+ pub update_rate_in_milliseconds: u64,
+ pub show_average_cpu: bool,
+ pub current_application_position: ApplicationPosition,
+ pub current_zoom_level_percent: f64, // Make at most 200, least 50?
+ pub data: data_collection::Data,
+ pub scroll_direction: ScrollDirection,
+ pub previous_disk_position: i64,
+ pub previous_temp_position: i64,
+ pub previous_process_position: i64,
+ awaiting_second_d: bool,
+ pub use_dot: bool,
+ pub show_help: bool,
+ pub is_frozen: bool,
}
impl App {
- pub fn new(show_average_cpu : bool, temperature_type : temperature::TemperatureType, update_rate_in_milliseconds : u64, use_dot : bool) -> App {
+ pub fn new(show_average_cpu: bool, temperature_type: temperature::TemperatureType, update_rate_in_milliseconds: u64, use_dot: bool) -> App {
App {
- process_sorting_type : processes::ProcessSorting::CPU,
- process_sorting_reverse : true,
- to_be_resorted : false,
- currently_selected_process_position : 0,
- currently_selected_disk_position : 0,
- currently_selected_temperature_position : 0,
+ process_sorting_type: processes::ProcessSorting::CPU,
+ process_sorting_reverse: true,
+ to_be_resorted: false,
+ currently_selected_process_position: 0,
+ currently_selected_disk_position: 0,
+ currently_selected_temperature_position: 0,
temperature_type,
update_rate_in_milliseconds,
show_average_cpu,
- current_application_position : ApplicationPosition::PROCESS,
- current_zoom_level_percent : 100.0,
- data : data_collection::Data::default(),
- scroll_direction : ScrollDirection::DOWN,
- previous_process_position : 0,
- previous_disk_position : 0,
- previous_temp_position : 0,
- awaiting_second_d : false,
+ current_application_position: ApplicationPosition::PROCESS,
+ current_zoom_level_percent: 100.0,
+ data: data_collection::Data::default(),
+ scroll_direction: ScrollDirection::DOWN,
+ previous_process_position: 0,
+ previous_disk_position: 0,
+ previous_temp_position: 0,
+ awaiting_second_d: false,
use_dot,
- show_help : false,
- is_frozen : false,
+ show_help: false,
+ is_frozen: false,
}
}
- pub fn on_enter(&mut self) {
- }
+ pub fn on_enter(&mut self) {}
pub fn on_esc(&mut self) {
if self.show_help {
@@ -79,15 +78,14 @@ impl App {
}
// TODO: How should we make it for process panel specific hotkeys? Only if we're on process panel? Or what?
- pub fn on_key(&mut self, c : char) {
+ pub fn on_key(&mut self, c: char) {
if !self.show_help {
match c {
'd' => {
if self.awaiting_second_d {
self.awaiting_second_d = false;
self.kill_highlighted_process().unwrap_or(());
- }
- else {
+ } else {
self.awaiting_second_d = true;
}
}
@@ -223,7 +221,7 @@ impl App {
self.scroll_direction = ScrollDirection::DOWN;
}
- fn change_process_position(&mut self, num_to_change_by : i64) {
+ 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
{
@@ -231,7 +229,7 @@ impl App {
}
}
- fn change_temp_position(&mut self, num_to_change_by : i64) {
+ 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 < self.data.list_of_temperature_sensor.len() as i64
{
@@ -239,7 +237,7 @@ impl App {
}
}
- fn change_disk_position(&mut self, num_to_change_by : i64) {
+ 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 < self.data.list_of_disks.len() as i64
{
diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs
index e89a7390..bb03deb1 100644
--- a/src/app/data_collection.rs
+++ b/src/app/data_collection.rs
@@ -11,13 +11,13 @@ pub mod network;
pub mod processes;
pub mod temperature;
-fn set_if_valid<T : std::clone::Clone>(result : &Result<T, crate::utils::error::RustopError>, value_to_set : &mut T) {
+fn set_if_valid<T: std::clone::Clone>(result: &Result<T, crate::utils::error::RustopError>, value_to_set: &mut T) {
if let Ok(result) = result {
*value_to_set = (*result).clone();
}
}
-fn push_if_valid<T : std::clone::Clone>(result : &Result<T, crate::utils::error::RustopError>, vector_to_push : &mut Vec<T>) {
+fn push_if_valid<T: std::clone::Clone>(result: &Result<T, crate::utils::error::RustopError>, vector_to_push: &mut Vec<T>) {
if let Ok(result) = result {
vector_to_push.push(result.clone());
}
@@ -25,47 +25,47 @@ fn push_if_valid<T : std::clone::Clone>(result : &Result<T, crate::utils::error:
#[derive(Default, Clone)]
pub struct Data {
- pub list_of_cpu_packages : Vec<cpu::CPUPackage>,
- pub list_of_io : Vec<disks::IOPackage>,
- pub list_of_physical_io : Vec<disks::IOPackage>,
- pub memory : Vec<mem::MemData>,
- pub swap : Vec<mem::MemData>,
- pub list_of_temperature_sensor : Vec<temperature::TempData>,
- pub network : Vec<network::NetworkData>,
- pub list_of_processes : Vec<processes::ProcessData>, // Only need to keep a list of processes...
- pub list_of_disks : Vec<disks::DiskData>, // Only need to keep a list of disks and their data
+ pub list_of_cpu_packages: Vec<cpu::CPUPackage>,
+ pub list_of_io: Vec<disks::IOPackage>,
+ pub list_of_physical_io: Vec<disks::IOPackage>,
+ pub memory: Vec<mem::MemData>,
+ pub swap: Vec<mem::MemData>,
+ pub list_of_temperature_sensor: Vec<temperature::TempData>,
+ pub network: Vec<network::NetworkData>,
+ pub list_of_processes: Vec<processes::ProcessData>, // Only need to keep a list of processes...
+ pub list_of_disks: Vec<disks::DiskData>, // Only need to keep a list of disks and their data
}
pub struct DataState {
- pub data : Data,
- first_run : bool,
- sys : System,
- stale_max_seconds : u64,
- prev_pid_stats : HashMap<String, (f64, Instant)>,
- prev_idle : f64,
- prev_non_idle : f64,
- temperature_type : temperature::TemperatureType,
- last_clean : Instant, // Last time stale data was cleared
+ pub data: Data,
+ first_run: bool,
+ sys: System,
+ stale_max_seconds: u64,
+ prev_pid_stats: HashMap<String, (f64, Instant)>,
+ prev_idle: f64,
+ prev_non_idle: f64,
+ temperature_type: temperature::TemperatureType,
+ last_clean: Instant, // Last time stale data was cleared
}
impl Default for DataState {
fn default() -> Self {
DataState {
- data : Data::default(),
- first_run : true,
- sys : System::new(),
- stale_max_seconds : constants::STALE_MAX_MILLISECONDS / 1000,
- prev_pid_stats : HashMap::new(),
- prev_idle : 0_f64,
- prev_non_idle : 0_f64,
- temperature_type : temperature::TemperatureType::Celsius,
- last_clean : Instant::now(),
+ data: Data::default(),
+ first_run: true,
+ sys: System::new(),
+ stale_max_seconds: constants::STALE_MAX_MILLISECONDS / 1000,
+ prev_pid_stats: HashMap::new(),
+ prev_idle: 0_f64,
+ prev_non_idle: 0_f64,
+ temperature_type: temperature::TemperatureType::Celsius,
+ last_clean: Instant::now(),
}
}
}
impl DataState {
- pub fn set_temperature_type(&mut self, temperature_type : temperature::TemperatureType) {
+ pub fn set_temperature_type(&mut self, temperature_type: temperature::TemperatureType) {
self.temperature_type = temperature_type;
}
@@ -113,7 +113,7 @@ impl DataState {
let current_instant = std::time::Instant::now();
if current_instant.duration_since(self.last_clean).as_secs() > self.stale_max_seconds {
- let stale_list : Vec<_> = self
+ let stale_list: Vec<_> = self
.prev_pid_stats
.iter()
.filter(|&(_, &v)| current_instant.duration_since(v.1).as_secs() > self.stale_max_seconds)
diff --git a/src/app/data_collection/cpu.rs b/src/app/data_collection/cpu.rs
index 0a44bac8..0fd5d233 100644
--- a/src/app/data_collection/cpu.rs
+++ b/src/app/data_collection/cpu.rs
@@ -3,29 +3,29 @@ use sysinfo::{ProcessorExt, System, SystemExt};
#[derive(Clone)]
pub struct CPUData {
- pub cpu_name : Box<str>,
- pub cpu_usage : f64,
+ pub cpu_name: Box<str>,
+ pub cpu_usage: f64,
}
#[derive(Clone)]
pub struct CPUPackage {
- pub cpu_vec : Vec<CPUData>,
- pub instant : Instant,
+ pub cpu_vec: Vec<CPUData>,
+ pub instant: Instant,
}
-pub fn get_cpu_data_list(sys : &System) -> crate::utils::error::Result<CPUPackage> {
+pub fn get_cpu_data_list(sys: &System) -> crate::utils::error::Result<CPUPackage> {
let cpu_data = sys.get_processor_list();
let mut cpu_vec = Vec::new();
for cpu in cpu_data {
cpu_vec.push(CPUData {
- cpu_name : Box::from(cpu.get_name()),
- cpu_usage : f64::from(cpu.get_cpu_usage()) * 100_f64,
+ cpu_name: Box::from(cpu.get_name()),
+ cpu_usage: f64::from(cpu.get_cpu_usage()) * 100_f64,
})
}
Ok(CPUPackage {
cpu_vec,
- instant : Instant::now(),
+ instant: Instant::now(),
})
}
diff --git a/src/app/data_collection/mem.rs b/src/app/data_collection/mem.rs
index 929ee326..f4a8be1a 100644
--- a/src/app/data_collection/mem.rs
+++ b/src/app/data_collection/mem.rs
@@ -3,18 +3,18 @@ use std::time::Instant;
#[derive(Clone)]
pub struct MemData {
- pub mem_total_in_mb : u64,
- pub mem_used_in_mb : u64,
- pub instant : Instant,
+ pub mem_total_in_mb: u64,
+ pub mem_used_in_mb: u64,
+ pub instant: Instant,
}
pub async fn get_mem_data_list() -> crate::utils::error::Result<MemData> {
let memory = heim::memory::memory().await?;
Ok(MemData {
- mem_total_in_mb : memory.total().get::<information::megabyte>(),
- mem_used_in_mb : memory.total().get::<information::megabyte>() - memory.available().get::<information::megabyte>(),
- instant : Instant::now(),
+ mem_total_in_mb: memory.total().get::<information::megabyte>(),
+ mem_used_in_mb: memory.total().get::<information::megabyte>() - memory.available().get::<information::megabyte>(),
+ instant: Instant::now(),
})
}
@@ -22,8 +22,8 @@ pub async fn get_swap_data_list() -> crate::utils::error::Result<MemData> {
let memory = heim::memory::swap().await?;
Ok(MemData {
- mem_total_in_mb : memory.total().get::<information::megabyte>(),
- mem_used_in_mb : memory.used().get::<information::megabyte>(),
- instant : Instant::now(),
+ mem_total_in_mb: memory.total().get::<information::megabyte>(),
+ mem_used_in_mb: memory.used().get::<information::megabyte>(),
+ instant: Instant::now(),
})
}
diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs
index 7e020968..982ebfaa 100644
--- a/src/app/data_collection/processes.rs
+++ b/src/app/data_collection/processes.rs
@@ -18,14 +18,14 @@ impl Default for ProcessSorting {
// Possible process info struct?
#[derive(Clone, Default)]
pub struct ProcessData {
- pub pid : u32,
- pub cpu_usage_percent : f64,
- pub mem_usage_percent : Option<f64>,
- pub mem_usage_kb : Option<u64>,
- pub command : String,
+ pub pid: u32,
+ pub cpu_usage_percent: f64,
+ pub mem_usage_percent: Option<f64>,
+ pub mem_usage_kb: Option<u64>,
+ pub command: String,
}
-fn vangelis_cpu_usage_calculation(prev_idle : &mut f64, prev_non_idle : &mut f64) -> std::io::Result<(f64, f64)> {
+fn vangelis_cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> std::io::Result<(f64, f64)> {
// Named after this SO answer: https://stackoverflow.com/a/23376195
let mut path = std::path::PathBuf::new();
path.push("/proc");
@@ -43,15 +43,15 @@ fn vangelis_cpu_usage_calculation(prev_idle : &mut f64, prev_non_idle : &mut f64
return Ok((1.0, 0.0)); // TODO: This is not the greatest...
}
- let user : f64 = val[1].parse::<_>().unwrap_or(0_f64);
- let nice : f64 = val[2].parse::<_>().unwrap_or(0_f64);
- let system : f64 = val[3].parse::<_>().unwrap_or(0_f64);
- let idle : f64 = val[4].parse::<_>().unwrap_or(0_f64);
- let iowait : f64 = val[5].parse::<_>().unwrap_or(0_f64);
- let irq : f64 = val[6].parse::<_>().unwrap_or(0_f64);
- let softirq : f64 = val[7].parse::<_>().unwrap_or(0_f64);
- let steal : f64 = val[8].parse::<_>().unwrap_or(0_f64);
- let guest : f64 = val[9].parse::<_>().unwrap_or(0_f64);
+ let user: f64 = val[1].parse::<_>().unwrap_or(0_f64);
+ let nice: f64 = val[2].parse::<_>().unwrap_or(0_f64);
+ let system: f64 = val[3].parse::<_>().unwrap_or(0_f64);
+ let idle: f64 = val[4].parse::<_>().unwrap_or(0_f64);
+ let iowait: f64 = val[5].parse::<_>().unwrap_or(0_f64);
+ let irq: f64 = val[6].parse::<_>().unwrap_or(0_f64);
+ let softirq: f64 = val[7].parse::<_>().unwrap_or(0_f64);
+ let steal: f64 = val[8].parse::<_>().unwrap_or(0_f64);
+ let guest: f64 = val[9].parse::<_>().unwrap_or(0_f64);
let idle = idle + iowait;
let non_idle = user + nice + system + irq + softirq + steal + guest;
@@ -59,8 +59,8 @@ fn vangelis_cpu_usage_calculation(prev_idle : &mut f64, prev_non_idle : &mut f64
let total = idle + non_idle;
let prev_total = *prev_idle + *prev_non_idle;
- let total_delta : f64 = total - prev_total;
- let idle_delta : f64 = idle - *prev_idle;
+ let total_delta: f64 = total - prev_total;
+ let idle_delta: f64 = idle - *prev_idle;
//debug!("Vangelis function: CPU PERCENT: {}", (total_delta - idle_delta) / total_delta * 100_f64);
@@ -69,8 +69,7 @@ fn vangelis_cpu_usage_calculation(prev_idle : &mut f64, prev_non_idle : &mut f64
let result = if total_delta - idle_delta != 0_f64 {
total_delta - idle_delta
- }
- else {
+ } else {
1_f64
};
@@ -79,29 +78,25 @@ fn vangelis_cpu_usage_calculation(prev_idle : &mut f64, prev_non_idle : &mut f64
Ok((result, cpu_percentage)) // This works, REALLY damn well. The percentage check is within like 2% of the sysinfo one.
}
-fn get_ordering<T : std::cmp::PartialOrd>(a_val : T, b_val : T, reverse_order : bool) -> std::cmp::Ordering {
+fn get_ordering<T: std::cmp::PartialOrd>(a_val: T, b_val: T, reverse_order: bool) -> std::cmp::Ordering {
if a_val > b_val {
if reverse_order {
std::cmp::Ordering::Less
- }
- else {
+ } else {
std::cmp::Ordering::Greater
}
- }
- else if a_val < b_val {
+ } else if a_val < b_val {
if reverse_order {
std::cmp::Ordering::Greater
- }
- else {
+ } else {
std::cmp::Ordering::Less
}
- }
- else {
+ } else {
std::cmp::Ordering::Equal
}
}
-fn get_process_cpu_stats(pid : u32) -> std::io::Result<f64> {
+fn get_process_cpu_stats(pid: u32) -> std::io::Result<f64> {
let mut path = std::path::PathBuf::new();
path.push("/proc");
path.push(&pid.to_string());
@@ -118,14 +113,11 @@ fn get_process_cpu_stats(pid : u32) -> std::io::Result<f64> {
}
/// Note that cpu_percentage should be represented WITHOUT the \times 100 factor!
-fn linux_cpu_usage(
- pid : u32, cpu_usage : f64, cpu_percentage : f64, previous_pid_stats : &mut HashMap<String, (f64, Instant)>,
-) -> std::io::Result<f64> {
+fn linux_cpu_usage(pid: u32, cpu_usage: f64, cpu_percentage: f64, previous_pid_stats: &mut HashMap<String, (f64, Instant)>) -> std::io::Result<f64> {
// Based heavily on https://stackoverflow.com/a/23376195 and https://stackoverflow.com/a/1424556
- let before_proc_val : f64 = if previous_pid_stats.contains_key(&pid.to_string()) {
+ let before_proc_val: f64 = if previous_pid_stats.contains_key(&pid.to_string()) {
previous_pid_stats.get(&pid.to_string()).unwrap_or(&(0_f64, Instant::now())).0
- }
- else {
+ } else {
0_f64
};
let after_proc_val = get_process_cpu_stats(pid)?;
@@ -145,15 +137,15 @@ fn linux_cpu_usage(
}
fn convert_ps(
- process : &str, cpu_usage : f64, cpu_percentage : f64, prev_pid_stats : &mut HashMap<String, (f64, Instant)>,
+ process: &str, cpu_usage: f64, cpu_percentage: f64, prev_pid_stats: &mut HashMap<String, (f64, Instant)>,
) -> std::io::Result<ProcessData> {
if process.trim().to_string().is_empty() {
return Ok(ProcessData {
- pid : 0,
- command : "".to_string(),
- mem_usage_percent : None,
- mem_usage_kb : None,
- cpu_usage_percent : 0_f64,
+ pid: 0,
+ command: "".to_string(),
+ mem_usage_percent: None,
+ mem_usage_kb: None,
+ cpu_usage_percent: 0_f64,
});
}
@@ -165,15 +157,15 @@ fn convert_ps(
pid,
command,
mem_usage_percent,
- mem_usage_kb : None,
- cpu_usage_percent : linux_cpu_usage(pid, cpu_usage, cpu_percentage, prev_pid_stats)?,
+ mem_usage_kb: None,
+ cpu_usage_percent: linux_cpu_usage(pid, cpu_usage, cpu_percentage, prev_pid_stats)?,
})
}
pub async fn get_sorted_processes_list(
- sys : &System, prev_idle : &mut f64, prev_non_idle : &mut f64, prev_pid_stats : &mut std::collections::HashMap<String, (f64, Instant)>,
+ sys: &System, prev_idle: &mut f64, prev_non_idle: &mut f64, prev_pid_stats: &mut std::collections::HashMap<String, (f64, Instant)>,
) -> crate::utils::error::Result<Vec<ProcessData>> {
- let mut process_vector : Vec<ProcessData> = Vec::new();
+ let mut process_vector: Vec<ProcessData> = Vec::new();
if cfg!(target_os = "linux") {
// Linux specific - this is a massive pain... ugh.
@@ -192,26 +184,23 @@ pub async fn get_sorted_processes_list(
}
}
}
- }
- else if cfg!(target_os = "windows") {
+ } else if cfg!(target_os = "windows") {
// Windows
let process_hashmap = sys.get_process_list();
for process_val in process_hashmap.values() {
process_vector.push(ProcessData {
- pid : process_val.pid() as u32,
- command : process_val.name().to_string(),
- mem_usage_percent : None,
- mem_usage_kb : Some(process_val.memory()),
- cpu_usage_percent : f64::from(process_val.cpu_usage()),
+ pid: process_val.pid() as u32,
+ command: process_val.name().to_string(),
+ mem_usage_percent: None,
+ mem_usage_kb: Some(process_val.memory()),
+ cpu_usage_percent: f64::from(process_val.cpu_usage()),
});
}
- }
- else if cfg!(target_os = "macos") {
+ } else if cfg!(target_os = "macos") {
// TODO: macOS
debug!("Mac");
- }
- else {
+ } else {
// TODO: Others?
debug!("Else");
// Solaris: https://stackoverflow.com/a/4453581
@@ -220,7 +209,7 @@ pub async fn get_sorted_processes_list(
Ok(process_vector)
}
-pub fn sort_processes(process_vector : &mut Vec<ProcessData>, sorting_method : &ProcessSorting, reverse_order : bool) {
+pub fn sort_processes(process_vector: &mut Vec<ProcessData>, sorting_method: &ProcessSorting, reverse_order: bool) {
match sorting_method {
// Always sort alphabetically first!
ProcessSorting::CPU => {
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs
index 06ebeb0e..46396a78 100644
--- a/src/app/process_killer.rs
+++ b/src/app/process_killer.rs
@@ -18,7 +18,7 @@ struct Process(HANDLE);
#[cfg(target_os = "windows")]
impl Process {
- fn open(pid : DWORD) -> Result<Process, String> {
+ fn open(pid: DWORD) -> Result<Process, String> {
let pc = unsafe { OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE, 0, pid) };
if pc == null_mut() {
return Err("!OpenProcess".to_string());
@@ -33,23 +33,20 @@ impl Process {
}
/// Kills a process, given a PID.
-pub fn kill_process_given_pid(pid : u64) -> 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()?;
- }
- else if cfg!(target_os = "windows") {
+ } else if cfg!(target_os = "windows") {
#[cfg(target_os = "windows")]
let process = Process::open(pid as DWORD)?;
#[cfg(target_os = "windows")]
process.kill()?;
- }
- else if cfg!(target_os = "macos") {
+ } else if cfg!(target_os = "macos") {
// TODO: macOS
// See how sysinfo does it... https://docs.rs/sysinfo/0.9.5/sysinfo/trait.ProcessExt.html
debug!("Sorry, macOS support is not implemented yet!");
- }
- else {
+ } else {
// TODO: Others?
debug!("Sorry, other support this is not implemented yet!");
}
diff --git a/src/canvas.rs b/src/canvas.rs
index f8c50577..ca16f1f1 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -1,5 +1,5 @@
use crate::{app, constants, utils::error};
-use tui_temp_fork::{
+use tui::{
backend,
layout::{Alignment, Constraint, Direction, Layout},
style::{Color, Modifier, Style},
@@ -7,7 +7,7 @@ use tui_temp_fork::{
Terminal,
};
-const COLOUR_LIST : [Color; 6] = [
+const COLOUR_LIST: [Color; 6] = [
Color::Red,
Color::Green,
Color::LightYellow,
@@ -15,29 +15,29 @@ const COLOUR_LIST : [Color; 6] = [
Color::LightCyan,
Color::LightMagenta,
];
-const TEXT_COLOUR : Color = Color::Gray;
-const GRAPH_COLOUR : Color = Color::Gray;
-const BORDER_STYLE_COLOUR : Color = Color::Gray;
-const HIGHLIGHTED_BORDER_STYLE_COLOUR : Color = Color::LightBlue;
+const TEXT_COLOUR: Color = Color::Gray;
+const GRAPH_COLOUR: Color = Color::Gray;
+const BORDER_STYLE_COLOUR: Color = Color::Gray;
+const HIGHLIGHTED_BORDER_STYLE_COLOUR: Color = Color::LightBlue;
#[derive(Default)]
pub struct CanvasData {
- pub rx_display : String,
- pub tx_display : String,
- pub network_data_rx : Vec<(f64, f64)>,
- pub network_data_tx : Vec<(f64, f64)>,
- pub disk_data : Vec<Vec<String>>,
- pub temp_sensor_data : Vec<Vec<String>>,
- pub process_data : Vec<Vec<String>>,
- pub mem_data : Vec<(f64, f64)>,
- pub mem_values : Vec<(u64, u64)>,
- pub swap_data : Vec<(f64, f64)>,
- pub cpu_data : Vec<(String, Vec<(f64, f64)>)>,
+ pub rx_display: String,
+ pub tx_display: String,
+ pub network_data_rx: Vec<(f64, f64)>,
+ pub network_data_tx: Vec<(f64, f64)>,
+ pub disk_data: Vec<Vec<String>>,
+ pub temp_sensor_data: Vec<Vec<String>>,
+ pub process_data: Vec<Vec<String>>,
+ pub mem_data: Vec<(f64, f64)>,
+ pub mem_values: Vec<(u64, u64)>,
+ pub swap_data: Vec<(f64, f64)>,
+ pub cpu_data: Vec<(String, Vec<(f64, f64)>)>,
}
-pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state : &mut app::App, canvas_data : &CanvasData) -> error::Result<()> {
- let border_style : Style = Style::default().fg(BORDER_STYLE_COLOUR);
- let highlighted_border_style : Style = Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR);
+pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mut app::App, canvas_data: &CanvasData) -> error::Result<()> {
+ let border_style: Style = Style::default().fg(BORDER_STYLE_COLOUR);
+ let highlighted_border_style: Style = Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR);
terminal.autoresize()?;
terminal.draw(|mut f| {
@@ -80,8 +80,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
.alignment(Alignment::Left)
.wrap(true)
.render(&mut f, middle_dialog_chunk[1]);
- }
- else {
+ } else {
let vertical_chunks = Layout::default()
.direction(Direction::Vertical)
.margin(1)
@@ -109,7 +108,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
// Set up blocks and their components
// CPU usage graph
{
- let x_axis : Axis<String> = Axis::default()
+ let x_axis: Axis<String> = Axis::default()
.style(Style::default().fg(GRAPH_COLOUR))
.bounds([0.0, constants::TIME_STARTS_FROM as f64 * 10.0]);
let y_axis = Axis::default()
@@ -117,7 +116,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
.bounds([-0.5, 100.5])
.labels(&["0%", "100%"]);
- let mut dataset_vector : Vec<Dataset> = Vec::new();
+ let mut dataset_vector: Vec<Dataset> = Vec::new();
for (i, cpu) in canvas_data.cpu_data.iter().enumerate() {
let mut avg_cpu_exist_offset = 0;
@@ -125,8 +124,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
if i == 0 {
// Skip, we want to render the average cpu last!
continue;
- }
- else {
+ } else {
avg_cpu_exist_offset = 1;
}
}
@@ -168,7 +166,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
//Memory usage graph
{
- let x_axis : Axis<String> = Axis::default()
+ let x_axis: Axis<String> = Axis::default()
.style(Style::default().fg(GRAPH_COLOUR))
.bounds([0.0, constants::TIME_STARTS_FROM as f64 * 10.0]);
let y_axis = Axis::default()
@@ -183,9 +181,9 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
canvas_data.mem_values[0].0 as f64 / 1024.0,
canvas_data.mem_values[0].1 as f64 / 1024.0
);
- let swap_name : String;
+ let swap_name: String;
- let mut mem_canvas_vec : Vec<Dataset> = vec![Dataset::default()
+ let mut mem_canvas_vec: Vec<Dataset> = vec![Dataset::default()
.name(&mem_name)
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
.style(Style::default().fg(Color::LightBlue))
@@ -238,7 +236,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
&mut app_state.currently_selected_temperature_position,
);
- let sliced_vec : Vec<Vec<String>> = (&canvas_data.temp_sensor_data[start_position as usize..]).to_vec();
+ let sliced_vec: Vec<Vec<String>> = (&canvas_data.temp_sensor_data[start_position as usize..]).to_vec();
let mut disk_counter = 0;
let temperature_rows = sliced_vec.iter().map(|disk| {
@@ -247,8 +245,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
if disk_counter == app_state.currently_selected_temperature_position - start_position {
disk_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan)
- }
- else {
+ } else {
if disk_counter >= 0 {
disk_counter += 1;
}
@@ -283,7 +280,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
&mut app_state.currently_selected_disk_position,
);
- let sliced_vec : Vec<Vec<String>> = (&canvas_data.disk_data[start_position as usize..]).to_vec();
+ let sliced_vec: Vec<Vec<String>> = (&canvas_data.disk_data[start_position as usize..]).to_vec();
let mut disk_counter = 0;
let disk_rows = sliced_vec.iter().map(|disk| {
@@ -292,8 +289,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
if disk_counter == app_state.currently_selected_disk_position - start_position {
disk_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan)
- }
- else {
+ } else {
if disk_counter >= 0 {
disk_counter += 1;
}
@@ -329,7 +325,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
// Network graph
{
- let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
+ let x_axis: Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
let y_axis = Axis::default()
.style(Style::default().fg(GRAPH_COLOUR))
.bounds([-0.5, 1_000_000.5])
@@ -384,7 +380,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
start_position, app_state.previous_process_position, app_state.currently_selected_process_position, num_rows
);*/
- let sliced_vec : Vec<Vec<String>> = (&canvas_data.process_data[start_position as usize..]).to_vec();
+ let sliced_vec: Vec<Vec<String>> = (&canvas_data.process_data[start_position as usize..]).to_vec();
let mut process_counter = 0;
let process_rows = sliced_vec.iter().map(|process| {
@@ -393,8 +389,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
if process_counter == app_state.currently_selected_process_position - start_position {
process_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan)
- }
- else {
+ } else {
if process_counter >= 0 {
process_counter += 1;
}
@@ -412,8 +407,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
let direction_val = if app_state.process_sorting_reverse {
"⯆".to_string()
- }
- else {
+ } else {
"⯅".to_string()
};
@@ -453,17 +447,15 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
}
fn get_start_position(
- num_rows : i64, scroll_direction : &app::ScrollDirection, previous_position : &mut i64, currently_selected_position : &mut i64,
+ num_rows: i64, scroll_direction: &app::ScrollDirection, previous_position: &mut i64, currently_selected_position: &mut i64,
) -> i64 {
match scroll_direction {
app::ScrollDirection::DOWN => {
if *currently_selected_position < num_rows {
0
- }
- else if *currently_selected_position - num_rows < *previous_position {
+ } else if *currently_selected_position - num_rows < *previous_position {
*previous_position
- }
- else {
+ } else {
*previous_position = *currently_selected_position - num_rows + 1;
*previous_position
}
@@ -472,8 +464,7 @@ fn get_start_position(
if *currently_selected_position == *previous_position - 1 {
*previous_position = if *previous_position > 0 { *previous_position - 1 } else { 0 };
*previous_position
- }
- else {
+ } else {
*previous_position
}
}
diff --git a/src/constants.rs b/src/constants.rs
index 98ab6aaf..be32a841 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -1,5 +1,5 @@
// TODO: Store like three minutes of data, then change how much is shown based on scaling!
-pub const STALE_MAX_MILLISECONDS : u64 = 180 * 1000; // We wish to store at most 60 seconds worth of data. This may change in the future, or be configurable.
-pub const TIME_STARTS_FROM : u64 = 60 * 1000; // TODO: Fix this
-pub const TICK_RATE_IN_MILLISECONDS : u64 = 200; // We use this as it's a good value to work with.
-pub const DEFAULT_REFRESH_RATE_IN_MILLISECONDS : u128 = 1000;
+pub const STALE_MAX_MILLISECONDS: u64 = 180 * 1000; // We wish to store at most 60 seconds worth of data. This may change in the future, or be configurable.
+pub const TIME_STARTS_FROM: u64 = 60 * 1000; // TODO: Fix this
+pub const TICK_RATE_IN_MILLISECONDS: u64 = 200; // We use this as it's a go