Update canvas to support network change on windows
This commit is contained in:
parent
95ef6c2c4c
commit
8098e45dcf
|
@ -56,9 +56,11 @@ pub async fn get_temperature_data(
|
||||||
component_name: component.get_label().to_string(),
|
component_name: component.get_label().to_string(),
|
||||||
temperature: match temp_type {
|
temperature: match temp_type {
|
||||||
TemperatureType::Celsius => component.get_temperature(),
|
TemperatureType::Celsius => component.get_temperature(),
|
||||||
TemperatureType::Kelvin => component.get_temperature() + 273.15,
|
TemperatureType::Kelvin => {
|
||||||
|
convert_celsius_to_kelvin(component.get_temperature())
|
||||||
|
}
|
||||||
TemperatureType::Fahrenheit => {
|
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)
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -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 DISK_HEADERS: [&str; 7] = ["Disk", "Mount", "Used", "Free", "Total", "R/s", "W/s"];
|
||||||
const TEMP_HEADERS: [&str; 2] = ["Sensor", "Temp"];
|
const TEMP_HEADERS: [&str; 2] = ["Sensor", "Temp"];
|
||||||
const MEM_HEADERS: [&str; 3] = ["Mem", "Usage", "Usage%"];
|
const MEM_HEADERS: [&str; 3] = ["Mem", "Usage", "Usage%"];
|
||||||
const NON_WINDOWS_NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"];
|
const NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"];
|
||||||
const WINDOWS_NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "", ""];
|
|
||||||
const FORCE_MIN_THRESHOLD: usize = 5;
|
const FORCE_MIN_THRESHOLD: usize = 5;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -49,11 +48,7 @@ lazy_static! {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
static ref NON_WINDOWS_NETWORK_HEADERS_LENS: Vec<usize> = NON_WINDOWS_NETWORK_HEADERS
|
static ref NETWORK_HEADERS_LENS: Vec<usize> = NETWORK_HEADERS
|
||||||
.iter()
|
|
||||||
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
static ref WINDOWS_NETWORK_HEADERS_LENS: Vec<usize> = WINDOWS_NETWORK_HEADERS
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -713,64 +708,45 @@ impl Painter {
|
||||||
let total_tx_display: String = app_state.canvas_data.total_tx_display.clone();
|
let total_tx_display: String = app_state.canvas_data.total_tx_display.clone();
|
||||||
|
|
||||||
// Gross but I need it to work...
|
// Gross but I need it to work...
|
||||||
let total_network = if cfg!(not(target_os = "windows")) {
|
let total_network = vec![vec![
|
||||||
vec![vec![
|
rx_display,
|
||||||
rx_display,
|
tx_display,
|
||||||
tx_display,
|
total_rx_display,
|
||||||
total_rx_display,
|
total_tx_display,
|
||||||
total_tx_display,
|
]];
|
||||||
]]
|
|
||||||
} else {
|
|
||||||
vec![vec![rx_display, tx_display]]
|
|
||||||
};
|
|
||||||
let mapped_network = total_network
|
let mapped_network = total_network
|
||||||
.iter()
|
.iter()
|
||||||
.map(|val| Row::StyledData(val.iter(), self.colours.text_style));
|
.map(|val| Row::StyledData(val.iter(), self.colours.text_style));
|
||||||
|
|
||||||
// Calculate widths
|
// Calculate widths
|
||||||
let width_ratios: Vec<f64>;
|
let width_ratios: Vec<f64> = vec![0.25, 0.25, 0.25, 0.25];
|
||||||
let lens: &Vec<usize>;
|
let lens: &Vec<usize> = &NETWORK_HEADERS_LENS;
|
||||||
let width = f64::from(draw_loc.width);
|
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 =
|
let variable_intrinsic_results =
|
||||||
get_variable_intrinsic_widths(width as u16, &width_ratios, lens);
|
get_variable_intrinsic_widths(width as u16, &width_ratios, lens);
|
||||||
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
|
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
Table::new(
|
Table::new(NETWORK_HEADERS.iter(), mapped_network)
|
||||||
if cfg!(not(target_os = "windows")) {
|
.block(
|
||||||
NON_WINDOWS_NETWORK_HEADERS
|
Block::default()
|
||||||
} else {
|
.borders(Borders::ALL)
|
||||||
WINDOWS_NETWORK_HEADERS
|
.title_style(self.colours.widget_title_style)
|
||||||
}
|
.border_style(match app_state.current_widget_selected {
|
||||||
.iter(),
|
app::WidgetPosition::Network => self.colours.highlighted_border_style,
|
||||||
mapped_network,
|
_ => self.colours.border_style,
|
||||||
)
|
}),
|
||||||
.block(
|
)
|
||||||
Block::default()
|
.header_style(self.colours.table_header_style)
|
||||||
.borders(Borders::ALL)
|
.style(self.colours.text_style)
|
||||||
.title_style(self.colours.widget_title_style)
|
.widths(
|
||||||
.border_style(match app_state.current_widget_selected {
|
&(intrinsic_widths
|
||||||
app::WidgetPosition::Network => self.colours.highlighted_border_style,
|
.into_iter()
|
||||||
_ => self.colours.border_style,
|
.map(|calculated_width| Constraint::Length(*calculated_width as u16))
|
||||||
}),
|
.collect::<Vec<_>>()),
|
||||||
)
|
)
|
||||||
.header_style(self.colours.table_header_style)
|
.render(f, draw_loc);
|
||||||
.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>(
|
fn draw_temp_table<B: backend::Backend>(
|
||||||
|
|
Loading…
Reference in New Issue