Refactoring.

This commit is contained in:
ClementTsang 2020-02-29 17:07:47 -05:00
parent eb2622467f
commit 4c98fe4fde
14 changed files with 246 additions and 234 deletions

View File

@ -3,7 +3,6 @@ max_width = 100
newline_style = "Unix" newline_style = "Unix"
reorder_imports = true reorder_imports = true
fn_args_layout = "Compressed" fn_args_layout = "Compressed"
hard_tabs = true
merge_derives = true merge_derives = true
reorder_modules = true reorder_modules = true
tab_spaces = 4 tab_spaces = 4

View File

@ -712,7 +712,8 @@ impl App {
pub fn on_up_key(&mut self) { pub fn on_up_key(&mut self) {
if !self.is_in_dialog() { if !self.is_in_dialog() {
if let WidgetPosition::ProcessSearch = self.current_widget_selected {} else { if let WidgetPosition::ProcessSearch = self.current_widget_selected {
} else {
self.decrement_position_count(); self.decrement_position_count();
} }
} }
@ -720,7 +721,8 @@ impl App {
pub fn on_down_key(&mut self) { pub fn on_down_key(&mut self) {
if !self.is_in_dialog() { if !self.is_in_dialog() {
if let WidgetPosition::ProcessSearch = self.current_widget_selected {} else { if let WidgetPosition::ProcessSearch = self.current_widget_selected {
} else {
self.increment_position_count(); self.increment_position_count();
} }
} }
@ -858,7 +860,8 @@ impl App {
let current_key_press_inst = Instant::now(); let current_key_press_inst = Instant::now();
if current_key_press_inst if current_key_press_inst
.duration_since(self.last_key_press) .duration_since(self.last_key_press)
.as_millis() > constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS .as_millis()
> constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS
{ {
self.reset_multi_tap_keys(); self.reset_multi_tap_keys();
} }
@ -1172,12 +1175,14 @@ impl App {
WidgetPosition::Process => { WidgetPosition::Process => {
self.app_scroll_positions self.app_scroll_positions
.process_scroll_state .process_scroll_state
.current_scroll_position = self.canvas_data.finalized_process_data.len() as u64 - 1 .current_scroll_position =
self.canvas_data.finalized_process_data.len() as u64 - 1
} }
WidgetPosition::Temp => { WidgetPosition::Temp => {
self.app_scroll_positions self.app_scroll_positions
.temp_scroll_state .temp_scroll_state
.current_scroll_position = self.canvas_data.temp_sensor_data.len() as u64 - 1 .current_scroll_position =
self.canvas_data.temp_sensor_data.len() as u64 - 1
} }
WidgetPosition::Disk => { WidgetPosition::Disk => {
self.app_scroll_positions self.app_scroll_positions

View File

@ -15,7 +15,7 @@
use std::time::Instant; use std::time::Instant;
use std::vec::Vec; use std::vec::Vec;
use crate::data_harvester::{cpu, Data, disks, mem, network, processes, temperature}; use crate::data_harvester::{cpu, disks, mem, network, processes, temperature, Data};
pub type TimeOffset = f64; pub type TimeOffset = f64;
pub type Value = f64; pub type Value = f64;

View File

@ -37,13 +37,15 @@ pub async fn get_temperature_data(
temperature: match temp_type { temperature: match temp_type {
TemperatureType::Celsius => sensor TemperatureType::Celsius => sensor
.current() .current()
.get::<thermodynamic_temperature::degree_celsius>(), .get::<thermodynamic_temperature::degree_celsius>(
),
TemperatureType::Kelvin => { TemperatureType::Kelvin => {
sensor.current().get::<thermodynamic_temperature::kelvin>() sensor.current().get::<thermodynamic_temperature::kelvin>()
} }
TemperatureType::Fahrenheit => sensor TemperatureType::Fahrenheit => sensor
.current() .current()
.get::<thermodynamic_temperature::degree_fahrenheit>(), .get::<thermodynamic_temperature::degree_fahrenheit>(
),
}, },
}); });
} }

View File

@ -5,9 +5,9 @@ use tui::{
backend, backend,
layout::{Alignment, Constraint, Direction, Layout, Rect}, layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Style}, style::{Color, Style},
Terminal,
terminal::Frame, terminal::Frame,
widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Paragraph, Row, Table, Text, Widget}, widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Paragraph, Row, Table, Text, Widget},
Terminal,
}; };
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
@ -679,7 +679,8 @@ impl Painter {
== app_state == app_state
.app_scroll_positions .app_scroll_positions
.cpu_scroll_state .cpu_scroll_state
.current_scroll_position - start_position .current_scroll_position
- start_position
{ {
self.colours.currently_selected_text_style self.colours.currently_selected_text_style
} else if app_state.app_config_fields.show_average_cpu && itx == 0 { } else if app_state.app_config_fields.show_average_cpu && itx == 0 {
@ -1001,7 +1002,8 @@ impl Painter {
== app_state == app_state
.app_scroll_positions .app_scroll_positions
.temp_scroll_state .temp_scroll_state
.current_scroll_position - start_position .current_scroll_position
- start_position
{ {
temp_row_counter = -1; temp_row_counter = -1;
self.colours.currently_selected_text_style self.colours.currently_selected_text_style
@ -1097,7 +1099,8 @@ impl Painter {
== app_state == app_state
.app_scroll_positions .app_scroll_positions
.disk_scroll_state .disk_scroll_state
.current_scroll_position - start_position .current_scroll_position
- start_position
{ {
disk_counter = -1; disk_counter = -1;
self.colours.currently_selected_text_style self.colours.currently_selected_text_style
@ -1397,7 +1400,8 @@ impl Painter {
== app_state == app_state
.app_scroll_positions .app_scroll_positions
.process_scroll_state .process_scroll_state
.current_scroll_position - start_position .current_scroll_position
- start_position
{ {
process_counter = -1; process_counter = -1;
self.colours.currently_selected_text_style self.colours.currently_selected_text_style

View File

@ -7,9 +7,9 @@ use constants::*;
use crate::{ use crate::{
app::{ app::{
App,
data_farmer, data_farmer,
data_harvester::{self, processes::ProcessHarvest}, data_harvester::{self, processes::ProcessHarvest},
App,
}, },
constants, constants,
utils::gen_util::{get_exact_byte_values, get_simple_byte_values}, utils::gen_util::{get_exact_byte_values, get_simple_byte_values},
@ -195,7 +195,8 @@ pub fn convert_mem_labels(current_data: &data_farmer::DataCollection) -> (String
(current_data.memory_harvest.mem_used_in_mb as f64 * 100.0 (current_data.memory_harvest.mem_used_in_mb as f64 * 100.0
/ current_data.memory_harvest.mem_total_in_mb as f64) / current_data.memory_harvest.mem_total_in_mb as f64)
.round() .round()
) + &format!( )
+ &format!(
" {:.1}GB/{:.1}GB", " {:.1}GB/{:.1}GB",
current_data.memory_harvest.mem_used_in_mb as f64 / 1024.0, current_data.memory_harvest.mem_used_in_mb as f64 / 1024.0,
(current_data.memory_harvest.mem_total_in_mb as f64 / 1024.0).round() (current_data.memory_harvest.mem_total_in_mb as f64 / 1024.0).round()
@ -211,7 +212,8 @@ pub fn convert_mem_labels(current_data: &data_farmer::DataCollection) -> (String
(current_data.swap_harvest.mem_used_in_mb as f64 * 100.0 (current_data.swap_harvest.mem_used_in_mb as f64 * 100.0
/ current_data.swap_harvest.mem_total_in_mb as f64) / current_data.swap_harvest.mem_total_in_mb as f64)
.round() .round()
) + &format!( )
+ &format!(
" {:.1}GB/{:.1}GB", " {:.1}GB/{:.1}GB",
current_data.swap_harvest.mem_used_in_mb as f64 / 1024.0, current_data.swap_harvest.mem_used_in_mb as f64 / 1024.0,
(current_data.swap_harvest.mem_total_in_mb as f64 / 1024.0).round() (current_data.swap_harvest.mem_total_in_mb as f64 / 1024.0).round()

View File

@ -20,19 +20,19 @@ use std::{
use crossterm::{ use crossterm::{
event::{ event::{
DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent, KeyModifiers, MouseEvent, poll, read, DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent,
poll, read, KeyModifiers, MouseEvent,
}, },
execute, execute,
style::Print, style::Print,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen},
terminal::LeaveAlternateScreen, terminal::LeaveAlternateScreen,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen},
}; };
use tui::{backend::CrosstermBackend, Terminal}; use tui::{backend::CrosstermBackend, Terminal};
use app::{ use app::{
App,
data_harvester::{self, processes::ProcessSorting}, data_harvester::{self, processes::ProcessSorting},
App,
}; };
use constants::*; use constants::*;
use data_conversion::*; use data_conversion::*;

View File

@ -1,7 +1,7 @@
use serde::Deserialize; use serde::Deserialize;
use crate::{ use crate::{
app::{self, App, data_harvester}, app::{self, data_harvester, App},
constants::*, constants::*,
utils::error::{self, BottomError}, utils::error::{self, BottomError},
}; };