summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2020-02-09 22:19:05 -0500
committerClementTsang <cjhtsang@uwaterloo.ca>2020-02-09 22:19:05 -0500
commit8098e45dcfd9f0b18cf85b373777ce47b8b15bc9 (patch)
tree40f5577982c9e6695cc2436b2de76316de20c4de /src
parent95ef6c2c4c3c9a1f0729878c8c3c0f4140f16e62 (diff)
Update canvas to support network change on windows
Diffstat (limited to 'src')
-rw-r--r--src/app/data_harvester/temperature.rs14
-rw-r--r--src/canvas.rs82
2 files changed, 41 insertions, 55 deletions
diff --git a/src/app/data_harvester/temperature.rs b/src/app/data_harvester/temperature.rs
index a0c468a3..dcaa986d 100644
--- a/src/app/data_harvester/temperature.rs
+++ b/src/app/data_harvester/temperature.rs
@@ -56,9 +56,11 @@ pub async fn get_temperature_data(
component_name: component.get_label().to_string(),
temperature: match temp_type {
TemperatureType::Celsius => component.get_temperature(),
- TemperatureType::Kelvin => component.get_temperature() + 273.15,
+ TemperatureType::Kelvin => {
+ convert_celsius_to_kelvin(component.get_temperature())
+ }
TemperatureType::Fahrenheit => {
- (component.get_temperature() * (9.0 / 5.0)) + 32.0
+ convert_celsius_to_fahrenheit(component.get_temperature())
}
},
});
@@ -85,3 +87,11 @@ pub async fn get_temperature_data(
Ok(temperature_vec)
}
+
+fn convert_celsius_to_kelvin(celsius: f32) -> f32 {
+ celsius + 273.15
+}
+
+fn convert_celsius_to_fahrenheit(celsius: f32) -> f32 {
+ (celsius * (9.0 / 5.0)) + 32.0
+}
diff --git a/src/canvas.rs b/src/canvas.rs
index 246ce415..13fb63e2 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -26,8 +26,7 @@ const CPU_LEGEND_HEADER: [&str; 2] = ["CPU", "Use%"];
const DISK_HEADERS: [&str; 7] = ["Disk", "Mount", "Used", "Free", "Total", "R/s", "W/s"];
const TEMP_HEADERS: [&str; 2] = ["Sensor", "Temp"];
const MEM_HEADERS: [&str; 3] = ["Mem", "Usage", "Usage%"];
-const NON_WINDOWS_NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"];
-const WINDOWS_NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "", ""];
+const NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"];
const FORCE_MIN_THRESHOLD: usize = 5;
lazy_static! {
@@ -49,11 +48,7 @@ lazy_static! {
.iter()
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
.collect::<Vec<_>>();
- static ref NON_WINDOWS_NETWORK_HEADERS_LENS: Vec<usize> = NON_WINDOWS_NETWORK_HEADERS
- .iter()
- .map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
- .collect::<Vec<_>>();
- static ref WINDOWS_NETWORK_HEADERS_LENS: Vec<usize> = WINDOWS_NETWORK_HEADERS
+ static ref NETWORK_HEADERS_LENS: Vec<usize> = NETWORK_HEADERS
.iter()
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
.collect::<Vec<_>>();
@@ -713,64 +708,45 @@ impl Painter {
let total_tx_display: String = app_state.canvas_data.total_tx_display.clone();
// Gross but I need it to work...
- let total_network = if cfg!(not(target_os = "windows")) {
- vec![vec![
- rx_display,
- tx_display,
- total_rx_display,
- total_tx_display,
- ]]
- } else {
- vec![vec![rx_display, tx_display]]
- };
+ let total_network = vec![vec![
+ rx_display,
+ tx_display,
+ total_rx_display,
+ total_tx_display,
+ ]];
let mapped_network = total_network
.iter()
.map(|val| Row::StyledData(val.iter(), self.colours.text_style));
// Calculate widths
- let width_ratios: Vec<f64>;
- let lens: &Vec<usize>;
+ let width_ratios: Vec<f64> = vec![0.25, 0.25, 0.25, 0.25];
+ let lens: &Vec<usize> = &NETWORK_HEADERS_LENS;
let width = f64::from(draw_loc.width);
- if cfg!(not(target_os = "windows")) {
- width_ratios = vec![0.25, 0.25, 0.25, 0.25];
- lens = &NON_WINDOWS_NETWORK_HEADERS_LENS;
- } else {
- width_ratios = vec![0.25, 0.25];
- lens = &WINDOWS_NETWORK_HEADERS_LENS;
- }
let variable_intrinsic_results =
get_variable_intrinsic_widths(width as u16, &width_ratios, lens);
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
// Draw
- Table::new(
- if cfg!(not(target_os = "windows")) {
- NON_WINDOWS_NETWORK_HEADERS
- } else {
- WINDOWS_NETWORK_HEADERS
- }
- .iter(),
- mapped_network,
- )
- .block(
- Block::default()
- .borders(Borders::ALL)
- .title_style(self.colours.widget_title_style)
- .border_style(match app_state.current_widget_selected {
- app::WidgetPosition::Network => self.colours.highlighted_border_style,
- _ => self.colours.border_style,
- }),
- )
- .header_style(self.colours.table_header_style)
- .style(self.colours.text_style)
- .widths(
- &(intrinsic_widths
- .into_iter()
- .map(|calculated_width| Constraint::Length(*calculated_width as u16))
- .collect::<Vec<_>>()),
- )
- .render(f, draw_loc);
+ Table::new(NETWORK_HEADERS.iter(), mapped_network)
+ .block(
+ Block::default()
+ .borders(Borders::ALL)
+ .title_style(self.colours.widget_title_style)
+ .border_style(match app_state.current_widget_selected {
+ app::WidgetPosition::Network => self.colours.highlighted_border_style,
+ _ => self.colours.border_style,
+ }),
+ )
+ .header_style(self.colours.table_header_style)
+ .style(self.colours.text_style)
+ .widths(
+ &(intrinsic_widths
+ .into_iter()
+ .map(|calculated_width| Constraint::Length(*calculated_width as u16))
+ .collect::<Vec<_>>()),
+ )
+ .render(f, draw_loc);
}
fn draw_temp_table<B: backend::Backend>(