diff options
author | ClementTsang <clementjhtsang@gmail.com> | 2020-01-07 23:40:53 -0500 |
---|---|---|
committer | ClementTsang <clementjhtsang@gmail.com> | 2020-01-07 23:40:53 -0500 |
commit | 0f2b4a7ba519d6a4d2e7c1dc212894551f98ce8b (patch) | |
tree | 71cb2de595dc820f1b766b80cd6e73e99b6a8944 | |
parent | 5a32404ed480e25352ef92d4ff29a5be40f09077 (diff) |
Formatting changes to be a bit more strict on line length
-rw-r--r-- | rustfmt.toml | 2 | ||||
-rw-r--r-- | src/app.rs | 56 | ||||
-rw-r--r-- | src/app/data_collection/disks.rs | 7 | ||||
-rw-r--r-- | src/app/data_collection/mem.rs | 3 | ||||
-rw-r--r-- | src/app/data_collection/network.rs | 3 | ||||
-rw-r--r-- | src/app/data_collection/processes.rs | 82 | ||||
-rw-r--r-- | src/app/data_collection/temperature.rs | 28 | ||||
-rw-r--r-- | src/app/process_killer.rs | 4 | ||||
-rw-r--r-- | src/canvas.rs | 328 | ||||
-rw-r--r-- | src/data_conversion.rs | 122 | ||||
-rw-r--r-- | src/main.rs | 25 | ||||
-rw-r--r-- | src/utils/error.rs | 25 | ||||
-rw-r--r-- | src/utils/gen_util.rs | 18 |
13 files changed, 518 insertions, 185 deletions
diff --git a/rustfmt.toml b/rustfmt.toml index 7aa76c5c..ff28a453 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,4 +1,4 @@ -max_width = 150 +max_width = 100 newline_style = "Unix" reorder_imports = true control_brace_style = "ClosingNextLine" @@ -60,7 +60,8 @@ pub struct App { impl App { pub fn new( - show_average_cpu: bool, temperature_type: temperature::TemperatureType, update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool, + show_average_cpu: bool, temperature_type: temperature::TemperatureType, + update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool, use_current_cpu_total: bool, ) -> App { App { @@ -151,7 +152,10 @@ impl App { // Forbid any char key presses when showing a dialog box... if !self.is_in_dialog() { let current_key_press_inst = Instant::now(); - if current_key_press_inst.duration_since(self.last_key_press).as_millis() > constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS { + if current_key_press_inst + .duration_since(self.last_key_press) + .as_millis() > constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS + { self.reset_multi_tap_keys(); } self.last_key_press = current_key_press_inst; @@ -163,7 +167,8 @@ impl App { self.awaiting_second_char = false; self.second_char = ' '; - let current_process = &self.canvas_data.process_data[self.currently_selected_process_position as usize]; + let current_process = &self.canvas_data.process_data + [self.currently_selected_process_position as usize]; self.to_delete_process = Some(current_process.clone()); self.show_dd = true; self.reset_multi_tap_keys(); @@ -188,7 +193,9 @@ impl App { } 'c' => { match self.process_sorting_type { - processes::ProcessSorting::CPU => self.process_sorting_reverse = !self.process_sorting_reverse, + processes::ProcessSorting::CPU => { + self.process_sorting_reverse = !self.process_sorting_reverse + } _ => { self.process_sorting_type = processes::ProcessSorting::CPU; self.process_sorting_reverse = true; @@ -199,7 +206,9 @@ impl App { } 'm' => { match self.process_sorting_type { - processes::ProcessSorting::MEM => self.process_sorting_reverse = !self.process_sorting_reverse, + processes::ProcessSorting::MEM => { + self.process_sorting_reverse = !self.process_sorting_reverse + } _ => { self.process_sorting_type = processes::ProcessSorting::MEM; self.process_sorting_reverse = true; @@ -212,7 +221,9 @@ impl App { // Disable if grouping if !self.enable_grouping { match self.process_sorting_type { - processes::ProcessSorting::PID => self.process_sorting_reverse = !self.process_sorting_reverse, + processes::ProcessSorting::PID => { + self.process_sorting_reverse = !self.process_sorting_reverse + } _ => { self.process_sorting_type = processes::ProcessSorting::PID; self.process_sorting_reverse = false; @@ -224,7 +235,9 @@ impl App { } 'n' => { match self.process_sorting_type { - processes::ProcessSorting::NAME => self.process_sorting_reverse = !self.process_sorting_reverse, + processes::ProcessSorting::NAME => { + self.process_sorting_reverse = !self.process_sorting_reverse + } _ => { self.process_sorting_type = processes::ProcessSorting::NAME; self.process_sorting_reverse = false; @@ -339,15 +352,25 @@ impl App { pub fn skip_to_last(&mut self) { if !self.is_in_dialog() { match self.current_application_position { - ApplicationPosition::Process => self.currently_selected_process_position = self.data.list_of_processes.len() as i64 - 1, - ApplicationPosition::Temp => self.currently_selected_temperature_position = self.data.list_of_temperature_sensor.len() as i64 - 1, - ApplicationPosition::Disk => self.currently_selected_disk_position = self.data.list_of_disks.len() as i64 - 1, + ApplicationPosition::Process => { + self.currently_selected_process_position = + self.data.list_of_processes.len() as i64 - 1 + } + ApplicationPosition::Temp => { + self.currently_selected_temperature_position = + self.data.list_of_temperature_sensor.len() as i64 - 1 + } + ApplicationPosition::Disk => { + self.currently_selected_disk_position = self.data.list_of_disks.len() as i64 - 1 + } ApplicationPosition::Cpu => { if let Some(cpu_package) = self.data.list_of_cpu_packages.last() { if self.show_average_cpu { - self.currently_selected_cpu_table_position = cpu_package.cpu_vec.len() as i64; + self.currently_selected_cpu_table_position = + cpu_package.cpu_vec.len() as i64; } else { - self.currently_selected_cpu_table_position = cpu_package.cpu_vec.len() as i64 - 1; + self.currently_selected_cpu_table_position = + cpu_package.cpu_vec.len() as i64 - 1; } } } @@ -403,7 +426,8 @@ impl App { 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 + < self.data.list_of_processes.len() as i64 { self.currently_selected_process_position += num_to_change_by; } @@ -411,7 +435,8 @@ impl App { 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 + && self.currently_selected_temperature_position + num_to_change_by + < self.data.list_of_temperature_sensor.len() as i64 { self.currently_selected_temperature_position += num_to_change_by; } @@ -419,7 +444,8 @@ impl App { 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 + && self.currently_selected_disk_position + num_to_change_by + < self.data.list_of_disks.len() as i64 { self.currently_selected_disk_position += num_to_change_by; } diff --git a/src/app/data_collection/disks.rs b/src/app/data_collection/disks.rs index d65e48a3..eec34d32 100644 --- a/src/app/data_collection/disks.rs +++ b/src/app/data_collection/disks.rs @@ -75,7 +75,12 @@ pub async fn get_disk_usage_list() -> crate::utils::error::Result<Vec<DiskData>> free_space: usage.free().get::<information::megabyte>(), used_space: usage.used().get::<information::megabyte>(), total_space: usage.total().get::<information::megabyte>(), - mount_point: Box::from(partition.mount_point().to_str().unwrap_or("Name Unavailable")), + mount_point: Box::from( + partition + .mount_point() + .to_str() + .unwrap_or("Name Unavailable"), + ), name: Box::from( partition .device() diff --git a/src/app/data_collection/mem.rs b/src/app/data_collection/mem.rs index 459464dc..87d69cd8 100644 --- a/src/app/data_collection/mem.rs +++ b/src/app/data_collection/mem.rs @@ -13,7 +13,8 @@ pub async fn get_mem_data_list() -> crate::utils::error::Result<MemData> { 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>(), + mem_used_in_mb: memory.total().get::<information::megabyte>() + - memory.available().get::<information::megabyte>(), instant: Instant::now(), }) } diff --git a/src/app/data_collection/network.rs b/src/app/data_collection/network.rs index 39bf4ad9..3a622ecf 100644 --- a/src/app/data_collection/network.rs +++ b/src/app/data_collection/network.rs @@ -15,7 +15,8 @@ pub struct NetworkData { } pub async fn get_network_data( - sys: &System, prev_net_rx_bytes: &mut u64, prev_net_tx_bytes: &mut u64, prev_net_access_time: &mut std::time::Instant, + sys: &System, prev_net_rx_bytes: &mut u64, prev_net_tx_bytes: &mut u64, + prev_net_access_time: &mut std::time::Instant, ) -> crate::utils::error::Result<NetworkData> { if cfg!(target_os = "windows") { let network_data = sys.get_network(); diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs index 6a3ebe80..15c9bb15 100644 --- a/src/app/data_collection/processes.rs +++ b/src/app/data_collection/processes.rs @@ -28,7 +28,9 @@ pub struct ProcessData { pub pid_vec: Option<Vec<u32>>, // Note that this is literally never unless we are in grouping mode. This is to save rewriting time. } -fn cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> error::Result<(f64, f64)> { +fn cpu_usage_calculation( + prev_idle: &mut f64, prev_non_idle: &mut f64, +) -> error::Result<(f64, f64)> { // From SO answer: https://stackoverflow.com/a/23376195 let mut path = std::path::PathBuf::new(); path.push("/proc"); @@ -91,12 +93,18 @@ fn cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> error: 1_f64 }; - let cpu_percentage = if total_delta != 0_f64 { result / total_delta } else { 0_f64 }; + let cpu_percentage = if total_delta != 0_f64 { + result / total_delta + } else { + 0_f64 + }; Ok((result, cpu_percentage)) } -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 { match a_val.partial_cmp(&b_val) { Some(x) => match x { Ordering::Greater => { @@ -137,11 +145,15 @@ 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)>, use_current_cpu_total: bool, + pid: u32, cpu_usage: f64, cpu_percentage: f64, + previous_pid_stats: &mut HashMap<String, (f64, Instant)>, use_current_cpu_total: bool, ) -> 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()) { - previous_pid_stats.get(&pid.to_string()).unwrap_or(&(0_f64, Instant::now())).0 + previous_pid_stats + .get(&pid.to_string()) + .unwrap_or(&(0_f64, Instant::now())) + .0 } else { 0_f64 }; @@ -156,7 +168,9 @@ fn linux_cpu_usage( (after_proc_val - before_proc_val) / cpu_usage * 100_f64 );*/ - let entry = previous_pid_stats.entry(pid.to_string()).or_insert((after_proc_val, Instant::now())); + let entry = previous_pid_stats + .entry(pid.to_string()) + .or_insert((after_proc_val, Instant::now())); *entry = (after_proc_val, Instant::now()); if use_current_cpu_total { Ok((after_proc_val - before_proc_val) / cpu_usage * 100_f64) @@ -166,7 +180,8 @@ fn linux_cpu_usage( } fn convert_ps( - process: &str, cpu_usage: f64, cpu_percentage: f64, prev_pid_stats: &mut HashMap<String, (f64, Instant)>, use_current_cpu_total: bool, + process: &str, cpu_usage: f64, cpu_percentage: f64, + prev_pid_stats: &mut HashMap<String, (f64, Instant)>, use_current_cpu_total: bool, ) -> std::io::Result<ProcessData> { if process.trim().to_string().is_empty() { return Ok(ProcessData { @@ -179,22 +194,39 @@ fn convert_ps( }); } - let pid = (&process[..11]).trim().to_string().parse::<u32>().unwrap_or(0); + let pid = (&process[..11]) + .trim() + .to_string() + .parse::<u32>() + .unwrap_or(0); let command = (&process[11..61]).trim().to_string(); - let mem_usage_percent = Some((&process[62..]).trim().to_string().parse::<f64>().unwrap_or(0_f64)); + let mem_usage_percent = Some( + (&process[62..]) + .trim() + .to_string() + .parse::<f64>() + .unwrap_or(0_f64), + ); Ok(ProcessData { pid, command, mem_usage_percent, mem_usage_kb: None, - cpu_usage_percent: linux_cpu_usage(pid, cpu_usage, cpu_percentage, prev_pid_stats, use_current_cpu_total)?, + cpu_usage_percent: linux_cpu_usage( + pid, + cpu_usage, + cpu_percentage, + prev_pid_stats, + use_current_cpu_total, + )?, pid_vec: None, }) } pub 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)>, use_current_cpu_total: bool, ) -> crate::utils::error::Result<Vec<ProcessData>> { let mut process_vector: Vec<ProcessData> = Vec::new(); @@ -202,7 +234,9 @@ pub fn get_sorted_processes_list( 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()?; + 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'); //debug!("{:?}", split_string); @@ -211,7 +245,13 @@ pub fn get_sorted_processes_list( let process_stream = split_string.collect::<Vec<&str>>(); for process in process_stream { - if let Ok(process_object) = convert_ps(process, cpu_usage, cpu_percentage, prev_pid_stats, use_current_cpu_total) { + if let Ok(process_object) = convert_ps( + process, + cpu_usage, + cpu_percentage, + prev_pid_stats, + use_current_cpu_total, + ) { if !process_object.command.is_empty() { process_vector.push(process_object); } @@ -259,20 +299,28 @@ pub 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, +) { // Always sort alphabetically first! process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, false)); match sorting_method { ProcessSorting::CPU => { - process_vector.sort_by(|a, b| get_ordering(a.cpu_usage_percent, b.cpu_usage_percent, reverse_order)); + process_vector.sort_by(|a, b| { + get_ordering(a.cpu_usage_percent, b.cpu_usage_percent, reverse_order) + }); } ProcessSorting::MEM => { - process_vector.sort_by(|a, b| get_ordering(a.mem_usage_percent, b.mem_usage_percent, reverse_order)); + process_vector.sort_by(|a, b| { + get_ordering(a.mem_usage_percent, b.mem_usage_percent, reverse_order) + }); } ProcessSorting::PID => { process_vector.sort_by(|a, b| get_ordering(a.pid, b.pid, reverse_order)); } - ProcessSorting::NAME => process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, reverse_order)), + ProcessSorting::NAME => { + process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, reverse_order)) + } } } diff --git a/src/app/data_collection/temperature.rs b/src/app/data_collection/temperature.rs index 4328fb78..1bee113e 100644 --- a/src/app/data_collection/temperature.rs +++ b/src/app/data_collection/temperature.rs @@ -22,7 +22,9 @@ impl Default for TemperatureType { } } -pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) -> crate::utils::error::Result<Vec<TempData>> { +pub async fn get_temperature_data( + sys: &System, temp_type: &TemperatureType, +) -> crate::utils::error::Result<Vec<TempData>> { let mut temperature_vec: Vec<TempData> = Vec::new(); if cfg!(target_os = "linux") { @@ -32,9 +34,17 @@ pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) -> temperature_vec.push(TempData { component_name: Box::from(sensor.unit()), temperature: match temp_type { - TemperatureType::Celsius => sensor.current().get::<thermodynamic_temperature::degree_celsius>(), - TemperatureType::Kelvin => sensor.current().get::<thermodynamic_temperature::kelvin>(), - TemperatureType::Fahrenheit => sensor.current().get::<thermodynamic_temperature::degree_fahrenheit>(), + TemperatureType::Celsius => sensor + .current() + .get::<thermodynamic_temperature::degree_celsius>( + ), + TemperatureType::Kelvin => { + sensor.current().get::<thermodynamic_temperature::kelvin>() + } + TemperatureType::Fahrenheit => sensor + .current() + .get::<thermodynamic_temperature::degree_fahrenheit>( + ), }, }); } @@ -47,7 +57,9 @@ pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) -> temperature: match temp_type { TemperatureType::Celsius => component.get_temperature(), TemperatureType::Kelvin => component.get_temperature() + 273.15, - TemperatureType::Fahrenheit => (component.get_temperature() * (9.0 / 5.0)) + 32.0, + TemperatureType::Fahrenheit => { + (component.get_temperature() * (9.0 / 5.0)) + 32.0 + } }, }); } @@ -65,7 +77,11 @@ pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) -> None => Ordering::Equal, }); - temperature_vec.sort_by(|a, b| a.component_name.partial_cmp(&b.component_name).unwrap_or(Ordering::Equal)); + temperature_vec.sort_by(|a, b| { + a.component_name + .partial_cmp(&b.component_name) + .unwrap_or(Ordering::Equal) + }); Ok(temperature_vec) } diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs index fe058bb9..9f1d8656 100644 --- a/src/app/process_killer.rs +++ b/src/app/process_killer.rs @@ -48,7 +48,9 @@ pub fn kill_process_given_pid(pid: u32) -> crate::utils::error::Result<()> { }); } else { return Err(BottomError::GenericError { - message: "Sorry, support operating systems outside the main three are not implemented yet!".to_string(), + message: + "Sorry, support operating systems outside the main three are not implemented yet!" + .to_string(), }); } diff --git a/src/canvas.rs b/src/canvas.rs index 99ba2043..0c9e75d8 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -24,7 +24,9 @@ lazy_static! { Text::raw("q, Ctrl-c to quit.\n"), Text::raw("Ctrl-r to reset all data.\n"), Text::raw("f to toggle freezing and unfreezing the display.\n"), - Text::raw("Ctrl+Up/k, Ctrl+Down/j, Ctrl+Left/h, Ctrl+Right/l to navigate between panels.\n"), + Text::raw( + "Ctrl+Up/k, Ctrl+Down/j, Ctrl+Left/h, Ctrl+Right/l to navigate between panels.\n" + ), Text::raw("Up and Down scrolls through a list.\n"), Text::raw("Esc to close a dialog window (help or dd confirmation).\n"), Text::raw("? to get this help screen.\n"), @@ -37,7 +39,8 @@ lazy_static! { ]; static ref COLOUR_LIST: Vec<Color> = gen_n_colours(constants::NUM_COLOURS); static ref CANVAS_BORDER_STYLE: Style = Style::default().fg(BORDER_STYLE_COLOUR); - static ref CANVAS_HIGHLIGHTED_BORDER_STYLE: Style = Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR); + static ref CANVAS_HIGHLIGHTED_BORDER_STYLE: Style = + Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR); } #[derive(Default)] @@ -85,7 +88,13 @@ fn gen_n_colours(num_to_gen: i32) -> Vec<Color> { } // Generate colours - let mut colour_vec: Vec<Color> = vec![Color::LightCyan, Color::LightYellow, Color::Red, Color::Green, Color::LightMagenta]; + let mut colour_vec: Vec<Color> = vec![ + Color::LightCyan, + Color::LightYellow, + Color::Red, + Color::Green, + Color::LightMagenta, + ]; let mut h: f32 = 0.4; // We don't need random colours... right? for _i in 0..num_to_gen { @@ -97,7 +106,9 @@ fn gen_n_colours(num_to_gen: i32) -> Vec<Color> { colour_vec } -pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mut app::App) -> error::Result<()> { +pub fn draw_data<B: backend::Backend>( + terminal: &mut Terminal<B>, app_state: &mut app::App, +) -> error::Result<()> { terminal.autoresize()?; terminal.draw(|mut f| { if app_state.show_help { @@ -105,17 +116,35 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu let vertical_dialog_chunk = Layout::default() .direction(Direction::Vertical) .margin(1) - .constraints([Constraint::Percentage(32), Constraint::Percentage(40), Constraint::Percentage(28)].as_ref()) + .constraints( + [ + Constraint::Percentage(32), + Constraint::Percentage(40), + Constraint::Percentage(28), + ] + .as_ref(), + ) .split(f.size()); let middle_dialog_chunk = Layout::default() .direction(Direction::Horizontal) .margin(0) - .constraints([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)].as_ref()) + .constraints( + [ + Constraint::Percentage(30), + Constraint::Percentage(40), + Constraint::Percentage(30), + ] + .as_ref(), + ) .split(vertical_dialog_chunk[1]); Paragraph::new(HELP_TEXT.iter()) - .block(Block::default().title("Help (Press Esc to close)").borders(Borders::ALL)) + .block( + Block::default() + .title("Help (Press Esc to close)") + .borders(Borders::ALL), + ) .style(Style::default().fg(Color::Gray)) .alignment(Alignment::Left) .wrap(true) @@ -124,20 +153,41 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu let vertical_dialog_chunk = Layout::default() .direction(Direction::Vertical) .margin(1) - .constraints([Constraint::Percentage(40), Constraint::Percentage(20), Constraint::Percentage(40)].as_ref()) + .constraints( + [ + Constraint::Percentage(40), + Constraint::Percentage(20), + Constraint::Percentage(40), + ] + .as_ref(), + ) .split(f.size()); let middle_dialog_chunk = Layout::default() .direction(Direction::Horizontal) .margin(0) - .constraints([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)].as_ref()) + .constraints( + [ + Constraint::Percentage(30), + Constraint::Percentage(40), + Constraint::Percentage(30), + ] + .as_ref(), + ) .split(vertical_dialog_chunk[1]); if let Some(dd_err) = app_state.dd_err.clone() { - let dd_text = [Text::raw(format!("\nFailure to properly kill the process - {}", dd_err))]; + let dd_text = [Text::raw(format!( + "\nFailure to properly kill the process - {}", + dd_err + ))]; Paragraph::new(dd_text.iter()) - .block(Block::default().title("Kill Process Error (Press Esc to close)").borders(Borders::ALL)) + .block( + Block::default() + .title("Kill Process Error (Press Esc to close)") + .borders(Borders::ALL), + ) .style(Style::default().fg(Color::Gray)) .alignment(Alignment::Center) .wrap(true) @@ -170,7 +220,14 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu let vertical_chunks = Layout::default() .direction(Direction::Vertical) .margin(1) - .constraints([Constraint::Percentage(33), Constraint::Percentage(34), Constraint::Percentage(34)].as_ref()) + .constraints( + [ + Constraint::Percentage(33), + Constraint::Percentage(34), + Constraint::Percentage(34), + ] + .as_ref(), + ) .split(f.size()); let middle_chunks = Layout::default() @@ -279,7 +336,10 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d cpu_entries_vec.push(( Style::default().fg(COLOUR_LIST[(i - avg_cpu_exist_offset) % COLOUR_LIST.len()]), - cpu.cpu_data.iter().map(<(f64, f64)>::from).collect::<Vec<_>>(), + cpu.cpu_data + .iter() + .map(<(f64, f64)>::from) + .collect::<Vec<_>>(), )); } @@ -287,7 +347,11 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d if let Some(avg_cpu_entry) = cpu_data.first() { cpu_entries_vec.push(( Style::default().fg(COLOUR_LIST[(cpu_data.len() - 1) % COLOUR_LIST.len()]), - avg_cpu_entry.cpu_data.iter().map(<(f64, f64)>::from).collect::<Vec<_>>(), + avg_cpu_entry + .cpu_data + .iter() + .map(<(f64, f64)>::from) + .collect::<Vec<_>>(), )); } } @@ -295,7 +359,11 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d for cpu_entry in &cpu_entries_vec { dataset_vector.push( Dataset::default() - .marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille }) + .marker(if app_state.use_dot { + Marker::Dot + } else { + Marker::Braille + }) .style(cpu_entry.0) .data(&(cpu_entry.1)), ); @@ -317,7 +385,9 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d .render(f, draw_loc); } -fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) { +fn draw_cpu_legend<B: backend::Backend>( + f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect, +) { let cpu_data: &[ConvertedCpuData] = &(app_state.canvas_data.cpu_data); let num_rows = i64::from(draw_loc.height) - 4; @@ -333,47 +403,55 @@ fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A for cpu in sliced_cpu_data { if let Some(cpu_data) = cpu.cpu_data.last() { - stringified_cpu_data.push(vec![cpu.cpu_name.clone(), format!("{:.0}%", cpu_data.usage.round())]); + stringified_cpu_data.push(vec![ + cpu.cpu_name.clone(), + format!("{:.0}%", cpu_data.usage.round()), + ]); } } let mut cpu_row_counter = 0; - let cpu_rows = stringified_cpu_data.iter().enumerate().map(|(itx, cpu_string_row)| { - Row::StyledData( - cpu_string_row.iter(), - match app_state.current_application_position { - app::ApplicationPosition::Cpu => { - if cpu_row_counter == app_state.currently_selected_cpu_table_position - start_position { - cpu_row_counter = -1; - Style::default().fg(Color::Black).bg(Color::Cyan) - } else { - if cpu_row_counter >= 0 { - cpu_row_counter += 1; + let cpu_rows = stringified_cpu_data + .iter() + .enumerate() + .map(|(itx, cpu_string_row)| { + Row::StyledData( + cpu_string_row.iter(), + match app_state.current_application_position { + app::ApplicationPosition::Cpu => { + if cpu_row_counter + == app_state.currently_selected_cpu_table_position - start_position + { + cpu_row_counter = -1; + Style::default().fg(Color::Black).bg(Color::Cyan) + } else { + if cpu_row_counter >= 0 { + cpu_row_counter += 1; + } + Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()]) } - Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()]) } - } - _ => Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()]), - }, - ) - }); + _ => Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()]), + }, + ) + }); Table::new(["CPU", "Use%"].iter(), cpu_rows) - .block( - Block::default() - .borders(Borders::ALL) - .border_style(match app_state.current_application_position { - app::ApplicationPosition::Cpu => *CANVAS_HIGHLIGHTED_BORDER_STYLE, - _ => *CANVAS_BORDER_STYLE, - }), - ) + .block(Block::default().borders(Borders::ALL).border_style( + match app_state.current_application_position { + app::ApplicationPosition::Cpu => *CANVAS_HIGHLIGHTED_BORDER_STYLE, + _ => *CANVAS_BORDER_STYLE, + }, + )) .header_style(Style::default().fg(Color::LightBlue)) .widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]) .render(f, draw_loc); } -fn _draw_memory_table<B: backend::Backend>(_f: &mut Frame<B>, _app_state: &app::App, _draw_loc: Rect) { +fn _draw_memory_table<B: backend::Backend>( + _f: &mut Frame<B>, _app_state: &app::App, _draw_loc: Rect, +) { todo!("Not implemented yet..."); // TODO: For basic mode } @@ -391,17 +469,23 @@ fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App .labels(&["0%", "100%"]); let mem_name = "RAM:".to_string() - + &format!("{:3}%", (mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64)) + &format!( - " {:.1}GB/{:.1}GB", - memory_labels.first().unwrap_or(&(0, 0)).0 as f64 / 1024.0, - memory_labels.first().unwrap_or(&(0, 0)).1 as f64 / 1024.0 - ); + "{:3}%", + (mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64) + ) + &format!( + " {:.1}GB/{:.1}GB", + memory_labels.first().unwrap_or(&(0, 0)).0 as f64 / 1024.0, + memory_labels.first().unwrap_or(&(0, 0)).1 as f64 / 1024.0 + ); let swap_name: String; let mut mem_canvas_vec: Vec<Dataset> = vec![Dataset::default() .name(&mem_name) - .marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille }) + .marker(if app_state.use_dot { + Marker::Dot + } else { + Marker::Braille + }) .style(Style::default().fg(COLOUR_LIST[0])) .data(&mem_data)]; @@ -409,16 +493,22 @@ fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App if let Some(last_canvas_result) = (&swap_data).last() { if last_canvas_result.1 >= 0.0 { swap_name = "SWP:".to_string() - + &format!("{:3}%", (swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64)) + &format!( - " {:.1}GB/{:.1}GB", - memory_labels[1].0 as f64 / 1024.0, - memory_labels[1].1 as f64 / 1024.0 - ); + "{:3}%", + (swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64) + ) + &format!( + " {:.1}GB/{:.1}GB", + memory_labels[1].0 as f64 / 1024.0, + memory_labels[1].1 as f64 / 1024.0 + ); mem_canvas_vec.push( Dataset::default() .name(&swap_name) - .marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille }) + .marker(if app_state.use_dot { + Marker::Dot + } else { + Marker::Braille + }) .style(Style::default().fg(COLOUR_LIST[1])) .data(&swap_data), ); @@ -446,7 +536,9 @@ fn draw_network_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::Ap let network_data_rx: &[(f64, f64)] = &(app_state.canvas_data.network_data_rx); let network_data_tx: &[(f64, f64)] = &(app_state.canvas_data.network_data_tx); - 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, 30_f64]) @@ -465,18 +557,28 @@ fn draw_network_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::Ap .y_axis(y_axis) .datasets(&[ Dataset::default() - .marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille }) + .marker(if app_state.use_dot { + Marker::Dot + } else { + Marker::Braille + }) .style(Style::default().fg(COLOUR_LIST[0])) .data(&network_data_rx), Dataset::default() - .marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille }) + .marker(if app_state.use_dot { + Marker::Dot + } else { + Marker::Braille + }) .style(Style::default().fg(COLOUR_LIST[1])) .data(&network_data_tx), ]) .render(f, draw_loc); } -fn draw_network_labels<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) { +fn draw_network_labels<B: backend::Backend>( + f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect, +) { let rx_display: String = app_state.canvas_data.rx_display.clone(); let tx_display: String = app_state.canvas_ |