diff --git a/src/app.rs b/src/app.rs index 4030dc3d8..e67e2300d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -20,7 +20,7 @@ use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation}; use crate::{ canvas::components::time_chart::LegendPosition, - collection::{processes::Pid, temperature}, + collection::processes::Pid, constants, utils::data_units::DataUnit, widgets::{ProcWidgetColumn, ProcWidgetMode}, @@ -38,7 +38,7 @@ pub enum AxisScaling { #[derive(Debug, Default, Eq, PartialEq)] pub struct AppConfigFields { pub update_rate: u64, - pub temperature_type: temperature::TemperatureType, + pub temperature_type: TemperatureType, pub use_dot: bool, pub cpu_left_legend: bool, pub show_average_cpu: bool, // TODO: Unify this in CPU options diff --git a/src/app/data/mod.rs b/src/app/data/mod.rs index 161f5c74a..d82b0d711 100644 --- a/src/app/data/mod.rs +++ b/src/app/data/mod.rs @@ -8,3 +8,6 @@ pub use process::ProcessData; mod store; pub use store::*; + +mod temperature; +pub use temperature::*; diff --git a/src/app/data/store.rs b/src/app/data/store.rs index fe3bbc0ab..25c2ae184 100644 --- a/src/app/data/store.rs +++ b/src/app/data/store.rs @@ -6,6 +6,7 @@ use std::{ #[cfg(feature = "battery")] use crate::collection::batteries; use crate::{ + app::AppConfigFields, collection::{cpu, disks, memory::MemHarvest, network, Data}, dec_bytes_per_second_string, widgets::TempWidgetData, @@ -18,7 +19,7 @@ use super::{ProcessData, TimeSeriesData}; /// TODO: Maybe reduce visibility of internal data, make it only accessible through DataStore? #[derive(Debug, Clone)] pub struct StoredData { - pub current_instant: Instant, // FIXME: (points_rework_v1) remove this? + pub last_update_time: Instant, // FIXME: (points_rework_v1) remove this? pub timeseries_data: TimeSeriesData, // FIXME: (points_rework_v1) Skip in basic? pub network_harvest: network::NetworkHarvest, pub ram_harvest: MemHarvest, @@ -44,7 +45,7 @@ pub struct StoredData { impl Default for StoredData { fn default() -> Self { StoredData { - current_instant: Instant::now(), + last_update_time: Instant::now(), timeseries_data: TimeSeriesData::default(), network_harvest: network::NetworkHarvest::default(), ram_harvest: MemHarvest::default(), @@ -77,24 +78,21 @@ impl StoredData { clippy::boxed_local, reason = "This avoids warnings on certain platforms (e.g. 32-bit)." )] - fn eat_data(&mut self, data: Box) { + fn eat_data(&mut self, data: Box, settings: &AppConfigFields) { let harvested_time = data.collection_time; self.timeseries_data.add(&data); - // Network if let Some(network) = data.network { self.network_harvest = network; } - // Memory, Swap if let Some(memory) = data.memory { self.ram_harvest = memory; } self.swap_harvest = data.swap; - // Cache memory #[cfg(not(target_os = "windows"))] { self.cache_harvest = data.cache; @@ -110,17 +108,14 @@ impl StoredData { self.gpu_harvest = gpu; } - // CPU if let Some(cpu) = data.cpu { self.cpu_harvest = cpu; } - // Load average if let Some(load_avg) = data.load_avg { self.load_avg_harvest = load_avg; } - // Temp // TODO: (points_rework_v1) the map might be redundant, the types are the same. self.temp_data = data .temperature_sensors @@ -129,41 +124,40 @@ impl StoredData { .into_iter() .map(|temp| TempWidgetData { sensor: temp.name, - temperature: temp.temperature.map(|v| v.into()), + temperature: temp + .temperature + .map(|c| settings.temperature_type.convert_temp_unit(c)), }) .collect() }) .unwrap_or_default(); - // Disks if let Some(disks) = data.disks { if let Some(io) = data.io { self.eat_disks(disks, io, harvested_time); } } - // Processes if let Some(list_of_processes) = data.list_of_processes { self.process_data.ingest(list_of_processes); } #[cfg(feature = "battery")] { - // Battery if let Some(list_of_batteries) = data.list_of_batteries { self.battery_harvest = list_of_batteries; } } - // And we're done eating. Update time and push the new entry! - self.current_instant = harvested_time; + // And we're done eating. Update time and push the new entry! + self.last_update_time = harvested_time; } fn eat_disks( &mut self, disks: Vec, io: disks::IoHarvest, harvested_time: Instant, ) { let time_since_last_harvest = harvested_time - .duration_since(self.current_instant) + .duration_since(self.last_update_time) .as_secs_f64(); for (itx, device) in disks.iter().enumerate() { @@ -315,8 +309,8 @@ impl DataStore { } /// Eat data. - pub fn eat_data(&mut self, data: Box) { - self.main.eat_data(data); + pub fn eat_data(&mut self, data: Box, settings: &AppConfigFields) { + self.main.eat_data(data, settings); } /// Clean data. diff --git a/src/app/data/temperature.rs b/src/app/data/temperature.rs new file mode 100644 index 000000000..9687cbeb2 --- /dev/null +++ b/src/app/data/temperature.rs @@ -0,0 +1,83 @@ +//! Code around temperature data. + +use std::{fmt::Display, str::FromStr}; + +#[derive(Clone, Debug, Copy, PartialEq, Eq, Default)] +pub enum TemperatureType { + #[default] + Celsius, + Kelvin, + Fahrenheit, +} + +impl FromStr for TemperatureType { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "fahrenheit" | "f" => Ok(TemperatureType::Fahrenheit), + "kelvin" | "k" => Ok(TemperatureType::Kelvin), + "celsius" | "c" => Ok(TemperatureType::Celsius), + _ => Err(format!( + "'{s}' is an invalid temperature type, use one of: [kelvin, k, celsius, c, fahrenheit, f]." + )), + } + } +} + +impl TemperatureType { + /// Given a temperature in Celsius, covert it if necessary for a different + /// unit. + pub fn convert_temp_unit(&self, celsius: f32) -> TypedTemperature { + match self { + TemperatureType::Celsius => TypedTemperature::Celsius(celsius.ceil() as u32), + TemperatureType::Kelvin => TypedTemperature::Kelvin((celsius + 273.15).ceil() as u32), + TemperatureType::Fahrenheit => { + TypedTemperature::Fahrenheit(((celsius * (9.0 / 5.0)) + 32.0).ceil() as u32) + } + } + } +} + +/// A temperature and its type. +#[derive(Debug, PartialEq, Clone, Eq, PartialOrd, Ord)] +pub enum TypedTemperature { + Celsius(u32), + Kelvin(u32), + Fahrenheit(u32), +} + +impl Display for TypedTemperature { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + TypedTemperature::Celsius(val) => write!(f, "{val}°C"), + TypedTemperature::Kelvin(val) => write!(f, "{val}K"), + TypedTemperature::Fahrenheit(val) => write!(f, "{val}°F"), + } + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn temp_conversions() { + const TEMP: f32 = 100.0; + + assert_eq!( + TemperatureType::Celsius.convert_temp_unit(TEMP), + TypedTemperature::Celsius(TEMP as u32), + ); + + assert_eq!( + TemperatureType::Kelvin.convert_temp_unit(TEMP), + TypedTemperature::Kelvin(373) + ); + + assert_eq!( + TemperatureType::Fahrenheit.convert_temp_unit(TEMP), + TypedTemperature::Fahrenheit(212) + ); + } +} diff --git a/src/collection.rs b/src/collection.rs index 47436a949..1fc923dff 100644 --- a/src/collection.rs +++ b/src/collection.rs @@ -27,7 +27,6 @@ use processes::Pid; #[cfg(feature = "battery")] use starship_battery::{Battery, Manager}; -use self::temperature::TemperatureType; use super::DataFilters; use crate::app::layout_manager::UsedWidgets; @@ -40,7 +39,7 @@ pub struct Data { #[cfg(not(target_os = "windows"))] pub cache: Option, pub swap: Option, - pub temperature_sensors: Option>, + pub temperature_sensors: Option>, pub network: Option, pub list_of_processes: Option>, pub disks: Option>, @@ -145,7 +144,6 @@ impl Default for SysinfoSource { pub struct DataCollector { pub data: Data, sys: SysinfoSource, - temperature_type: TemperatureType, use_current_cpu_total: bool, unnormalized_cpu: bool, last_collection_time: Instant, @@ -191,7 +189,6 @@ impl DataCollector { prev_idle: 0_f64, #[cfg(target_os = "linux")] prev_non_idle: 0_f64, - temperature_type: TemperatureType::Celsius, use_current_cpu_total: false, unnormalized_cpu: false, last_collection_time, @@ -242,10 +239,6 @@ impl DataCollector { self.widgets_to_harvest = used_widgets; } - pub fn set_temperature_type(&mut self, temperature_type: TemperatureType) { - self.temperature_type = temperature_type; - } - pub fn set_use_current_cpu_total(&mut self, use_current_cpu_total: bool) { self.use_current_cpu_total = use_current_cpu_total; } @@ -356,11 +349,9 @@ impl DataCollector { let mut local_gpu_total_mem: u64 = 0; #[cfg(feature = "nvidia")] - if let Some(data) = nvidia::get_nvidia_vecs( - &self.temperature_type, - &self.filters.temp_filter, - &self.widgets_to_harvest, - ) { + if let Some(data) = + nvidia::get_nvidia_vecs(&self.filters.temp_filter, &self.widgets_to_harvest) + { if let Some(mut temp) = data.temperature { if let Some(sensors) = &mut self.data.temperature_sensors { sensors.append(&mut temp); @@ -379,7 +370,6 @@ impl DataCollector { #[cfg(target_os = "linux")] if let Some(data) = amd::get_amd_vecs( - &self.temperature_type, &self.filters.temp_filter, &self.widgets_to_harvest, self.last_collection_time, @@ -435,18 +425,14 @@ impl DataCollector { fn update_temps(&mut self) { if self.widgets_to_harvest.use_temp { #[cfg(not(target_os = "linux"))] - if let Ok(data) = temperature::get_temperature_data( - &self.sys.temps, - &self.temperature_type, - &self.filters.temp_filter, - ) { + if let Ok(data) = + temperature::get_temperature_data(&self.sys.temps, &self.filters.temp_filter) + { self.data.temperature_sensors = data; } #[cfg(target_os = "linux")] - if let Ok(data) = - temperature::get_temperature_data(&self.temperature_type, &self.filters.temp_filter) - { + if let Ok(data) = temperature::get_temperature_data(&self.filters.temp_filter) { self.data.temperature_sensors = data; } } diff --git a/src/collection/amd.rs b/src/collection/amd.rs index d95df41d4..cb48b60a9 100644 --- a/src/collection/amd.rs +++ b/src/collection/amd.rs @@ -2,10 +2,7 @@ mod amdgpu_marketing; use crate::{ app::{filter::Filter, layout_manager::UsedWidgets}, - collection::{ - memory::MemHarvest, - temperature::{TempHarvest, TemperatureType}, - }, + collection::{memory::MemHarvest, temperature::TempSensorData}, }; use hashbrown::{HashMap, HashSet}; use std::{ @@ -18,7 +15,7 @@ use std::{ pub struct AMDGPUData { pub memory: Option>, - pub temperature: Option>, + pub temperature: Option>, pub procs: Option<(u64, Vec>)>, } @@ -402,8 +399,7 @@ fn get_amd_fdinfo(device_path: &Path) -> Option> { } pub fn get_amd_vecs( - temp_type: &TemperatureType, filter: &Option, widgets_to_harvest: &UsedWidgets, - prev_time: Instant, + filter: &Option, widgets_to_harvest: &UsedWidgets, prev_time: Instant, ) -> Option { let device_path_list = get_amd_devs()?; let interval = Instant::now().duration_since(prev_time); @@ -435,11 +431,9 @@ pub fn get_amd_vecs( if widgets_to_harvest.use_temp && Filter::optional_should_keep(filter, &device_name) { if let Some(temperatures) = get_amd_temp(&device_path) { for info in temperatures { - let temperature = temp_type.convert_temp_unit(info.temperature); - - temp_vec.push(TempHarvest { + temp_vec.push(TempSensorData { name: format!("{} {}", device_name, info.name), - temperature: Some(temperature), + temperature: Some(info.temperature), }); } } diff --git a/src/collection/nvidia.rs b/src/collection/nvidia.rs index 852597c4d..d6e42d8fc 100644 --- a/src/collection/nvidia.rs +++ b/src/collection/nvidia.rs @@ -7,17 +7,14 @@ use nvml_wrapper::{ use crate::{ app::{filter::Filter, layout_manager::UsedWidgets}, - collection::{ - memory::MemHarvest, - temperature::{TempHarvest, TemperatureType}, - }, + collection::{memory::MemHarvest, temperature::TempSensorData}, }; pub static NVML_DATA: OnceLock> = OnceLock::new(); pub struct GpusData { pub memory: Option>, - pub temperature: Option>, + pub temperature: Option>, pub procs: Option<(u64, Vec>)>, } @@ -47,7 +44,7 @@ fn init_nvml() -> Result { /// Returns the GPU data from NVIDIA cards. #[inline] pub fn get_nvidia_vecs( - temp_type: &TemperatureType, filter: &Option, widgets_to_harvest: &UsedWidgets, + filter: &Option, widgets_to_harvest: &UsedWidgets, ) -> Option { if let Ok(nvml) = NVML_DATA.get_or_init(init_nvml) { if let Ok(num_gpu) = nvml.device_count() { @@ -75,14 +72,12 @@ pub fn get_nvidia_vecs( && Filter::optional_should_keep(filter, &name) { if let Ok(temperature) = device.temperature(TemperatureSensor::Gpu) { - let temperature = temp_type.convert_temp_unit(temperature as f32); - - temp_vec.push(TempHarvest { + temp_vec.push(TempSensorData { name, - temperature: Some(temperature), + temperature: Some(temperature as f32), }); } else { - temp_vec.push(TempHarvest { + temp_vec.push(TempSensorData { name, temperature: None, }); diff --git a/src/collection/temperature.rs b/src/collection/temperature.rs index 2a2cf33b9..4887ace44 100644 --- a/src/collection/temperature.rs +++ b/src/collection/temperature.rs @@ -13,128 +13,11 @@ cfg_if::cfg_if! { } } -use std::{fmt::Display, str::FromStr}; - #[derive(Default, Debug, Clone)] -pub struct TempHarvest { +pub struct TempSensorData { + /// The name of the sensor. pub name: String, - pub temperature: Option, -} - -#[derive(Clone, Debug, Copy, PartialEq, Eq, Default)] -pub enum TemperatureType { - #[default] - Celsius, - Kelvin, - Fahrenheit, -} - -impl FromStr for TemperatureType { - type Err = String; - - fn from_str(s: &str) -> Result { - match s { - "fahrenheit" | "f" => Ok(TemperatureType::Fahrenheit), - "kelvin" | "k" => Ok(TemperatureType::Kelvin), - "celsius" | "c" => Ok(TemperatureType::Celsius), - _ => Err(format!( - "'{s}' is an invalid temperature type, use one of: [kelvin, k, celsius, c, fahrenheit, f]." - )), - } - } -} -impl TemperatureType { - /// Given a temperature in Celsius, covert it if necessary for a different - /// unit. - pub fn convert_temp_unit(&self, temp_celsius: f32) -> TypedTemperature { - fn celsius_to_kelvin(celsius: f32) -> TypedTemperature { - TypedTemperature::Kelvin(celsius + 273.15) - } - - fn celsius_to_fahrenheit(celsius: f32) -> TypedTemperature { - TypedTemperature::Fahrenheit((celsius * (9.0 / 5.0)) + 32.0) - } - - match self { - TemperatureType::Celsius => TypedTemperature::Celsius(temp_celsius), - TemperatureType::Kelvin => celsius_to_kelvin(temp_celsius), - TemperatureType::Fahrenheit => celsius_to_fahrenheit(temp_celsius), - } - } -} - -/// A temperature and its type. -#[derive(Debug, PartialEq, Clone)] -pub enum TypedTemperature { - Celsius(f32), - Kelvin(f32), - Fahrenheit(f32), -} - -/// A rounded temperature and its type. -/// -/// TODO: (points_rework_v1) this is kinda a hack, but it does work for now... -#[derive(Debug, PartialEq, Eq, Clone, PartialOrd, Ord)] -pub enum RoundedTypedTemperature { - Celsius(u32), - Kelvin(u32), - Fahrenheit(u32), -} - -impl From for RoundedTypedTemperature { - fn from(value: TypedTemperature) -> Self { - match value { - TypedTemperature::Celsius(val) => RoundedTypedTemperature::Celsius(val.ceil() as u32), - TypedTemperature::Kelvin(val) => RoundedTypedTemperature::Kelvin(val.ceil() as u32), - TypedTemperature::Fahrenheit(val) => { - RoundedTypedTemperature::Fahrenheit(val.ceil() as u32) - } - } - } -} - -impl Display for RoundedTypedTemperature { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - RoundedTypedTemperature::Celsius(val) => write!(f, "{val}°C"), - RoundedTypedTemperature::Kelvin(val) => write!(f, "{val}K"), - RoundedTypedTemperature::Fahrenheit(val) => write!(f, "{val}°F"), - } - } -} - -impl Display for TypedTemperature { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - TypedTemperature::Celsius(val) => write!(f, "{val}°C"), - TypedTemperature::Kelvin(val) => write!(f, "{val}K"), - TypedTemperature::Fahrenheit(val) => write!(f, "{val}°F"), - } - } -} - -#[cfg(test)] -mod test { - use crate::collection::temperature::{TemperatureType, TypedTemperature}; - - #[test] - fn temp_conversions() { - const TEMP: f32 = 100.0; - - assert_eq!( - TemperatureType::Celsius.convert_temp_unit(TEMP), - TypedTemperature::Celsius(TEMP), - ); - - assert_eq!( - TemperatureType::Kelvin.convert_temp_unit(TEMP), - TypedTemperature::Kelvin(373.15) - ); - - assert_eq!( - TemperatureType::Fahrenheit.convert_temp_unit(TEMP), - TypedTemperature::Fahrenheit(212.0) - ); - } + /// The temperature in Celsius. + pub temperature: Option, } diff --git a/src/collection/temperature/linux.rs b/src/collection/temperature/linux.rs index 4aaf1f52b..24adf66ce 100644 --- a/src/collection/temperature/linux.rs +++ b/src/collection/temperature/linux.rs @@ -8,7 +8,7 @@ use std::{ use anyhow::Result; use hashbrown::{HashMap, HashSet}; -use super::{TempHarvest, TemperatureType}; +use super::TempSensorData; use crate::app::filter::Filter; const EMPTY_NAME: &str = "Unknown"; @@ -16,7 +16,7 @@ const EMPTY_NAME: &str = "Unknown"; /// Returned results from grabbing hwmon/coretemp temperature sensor /// values/names. struct HwmonResults { - temperatures: Vec, + temperatures: Vec, num_hwmon: usize, } @@ -223,8 +223,8 @@ fn is_device_awake(path: &Path) -> bool { /// the device is already in ACPI D0. This has the notable issue that /// once this happens, the device will be *kept* on through the sensor /// reading, and not be able to re-enter ACPI D3cold. -fn hwmon_temperatures(temp_type: &TemperatureType, filter: &Option) -> HwmonResults { - let mut temperatures: Vec = vec![]; +fn hwmon_temperatures(filter: &Option) -> HwmonResults { + let mut temperatures: Vec = vec![]; let mut seen_names: HashMap = HashMap::new(); let (dirs, num_hwmon) = get_hwmon_candidates(); @@ -246,7 +246,7 @@ fn hwmon_temperatures(temp_type: &TemperatureType, filter: &Option) -> H if !is_device_awake(&file_path) { let name = finalize_name(None, None, &sensor_name, &mut seen_names); - temperatures.push(TempHarvest { + temperatures.push(TempSensorData { name, temperature: None, }); @@ -329,9 +329,9 @@ fn hwmon_temperatures(temp_type: &TemperatureType, filter: &Option) -> H // probing hwmon if not needed? if Filter::optional_should_keep(filter, &name) { if let Ok(temp_celsius) = parse_temp(&temp_path) { - temperatures.push(TempHarvest { + temperatures.push(TempSensorData { name, - temperature: Some(temp_type.convert_temp_unit(temp_celsius)), + temperature: Some(temp_celsius), }); } } @@ -351,9 +351,7 @@ fn hwmon_temperatures(temp_type: &TemperatureType, filter: &Option) -> H /// /// See [the Linux kernel documentation](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-thermal) /// for more details. -fn add_thermal_zone_temperatures( - temperatures: &mut Vec, temp_type: &TemperatureType, filter: &Option, -) { +fn add_thermal_zone_temperatures(temperatures: &mut Vec, filter: &Option) { let path = Path::new("/sys/class/thermal"); let Ok(read_dir) = path.read_dir() else { return; @@ -382,9 +380,9 @@ fn add_thermal_zone_temperatures( if let Ok(temp_celsius) = parse_temp(&temp_path) { let name = counted_name(&mut seen_names, name); - temperatures.push(TempHarvest { + temperatures.push(TempSensorData { name, - temperature: Some(temp_type.convert_temp_unit(temp_celsius)), + temperature: Some(temp_celsius), }); } } @@ -394,13 +392,11 @@ fn add_thermal_zone_temperatures( } /// Gets temperature sensors and data. -pub fn get_temperature_data( - temp_type: &TemperatureType, filter: &Option, -) -> Result>> { - let mut results = hwmon_temperatures(temp_type, filter); +pub fn get_temperature_data(filter: &Option) -> Result>> { + let mut results = hwmon_temperatures(filter); if results.num_hwmon == 0 { - add_thermal_zone_temperatures(&mut results.temperatures, temp_type, filter); + add_thermal_zone_temperatures(&mut results.temperatures, filter); } Ok(Some(results.temperatures)) diff --git a/src/collection/temperature/sysinfo.rs b/src/collection/temperature/sysinfo.rs index df8a29847..be4063e53 100644 --- a/src/collection/temperature/sysinfo.rs +++ b/src/collection/temperature/sysinfo.rs @@ -6,7 +6,7 @@ use super::{TempHarvest, TemperatureType}; use crate::app::filter::Filter; pub fn get_temperature_data( - components: &sysinfo::Components, temp_type: &TemperatureType, filter: &Option, + components: &sysinfo::Components, filter: &Option, ) -> Result>> { let mut temperatures: Vec = Vec::new(); @@ -16,7 +16,7 @@ pub fn get_temperature_data( if Filter::optional_should_keep(filter, &name) { temperatures.push(TempHarvest { name, - temperature: Some(temp_type.convert_temp_unit(component.temperature())), + temperature: Some(component.temperature()), }); } } @@ -25,7 +25,6 @@ pub fn get_temperature_data( // sensors. #[cfg(target_os = "freebsd")] { - use super::TypedTemperature; use sysctl::Sysctl; const KEY: &str = "hw.temperature"; @@ -35,15 +34,7 @@ pub fn get_temperature_data( if let Some(temp) = temp.as_temperature() { temperatures.push(TempHarvest { name, - temperature: Some(match temp_type { - TemperatureType::Celsius => { - TypedTemperature::Celsius(temp.celsius()) - } - TemperatureType::Kelvin => TypedTemperature::Kelvin(temp.kelvin()), - TemperatureType::Fahrenheit => { - TypedTemperature::Fahrenheit(temp.fahrenheit()) - } - }), + temperature: Some(temp.celsius()), }); } } diff --git a/src/lib.rs b/src/lib.rs index 33c05bca9..0648c7a65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,7 +218,6 @@ fn create_collection_thread( cancellation_token: Arc, app_config_fields: &AppConfigFields, filters: DataFilters, used_widget_set: UsedWidgets, ) -> JoinHandle<()> { - let temp_type = app_config_fields.temperature_type; let use_current_cpu_total = app_config_fields.use_current_cpu_total; let unnormalized_cpu = app_config_fields.unnormalized_cpu; let show_average_cpu = app_config_fields.show_average_cpu; @@ -228,7 +227,6 @@ fn create_collection_thread( let mut data_state = collection::DataCollector::new(filters); data_state.set_collection(used_widget_set); - data_state.set_temperature_type(temp_type); data_state.set_use_current_cpu_total(use_current_cpu_total); data_state.set_unnormalized_cpu(unnormalized_cpu); data_state.set_show_average_cpu(show_average_cpu); @@ -407,7 +405,7 @@ pub fn start_bottom() -> anyhow::Result<()> { try_drawing(&mut terminal, &mut app, &mut painter)?; } BottomEvent::Update(data) => { - app.data_store.eat_data(data); + app.data_store.eat_data(data, &app.app_config_fields); // This thing is required as otherwise, some widgets can't draw correctly w/o // some data (or they need to be re-drawn). diff --git a/src/options.rs b/src/options.rs index bdf5ac5b6..4dbb4d491 100644 --- a/src/options.rs +++ b/src/options.rs @@ -18,6 +18,7 @@ use std::{ use anyhow::{Context, Result}; use config::style::Styles; pub use config::Config; +use data::TemperatureType; pub(crate) use error::{OptionError, OptionResult}; use hashbrown::{HashMap, HashSet}; use indexmap::IndexSet; @@ -32,7 +33,6 @@ use self::{ use crate::{ app::{filter::Filter, layout_manager::*, *}, canvas::components::time_chart::LegendPosition, - collection::temperature::TemperatureType, constants::*, utils::data_units::DataUnit, widgets::*, diff --git a/src/widgets/temperature_table.rs b/src/widgets/temperature_table.rs index aa9bf8a66..83af383a7 100644 --- a/src/widgets/temperature_table.rs +++ b/src/widgets/temperature_table.rs @@ -1,12 +1,11 @@ use std::{borrow::Cow, cmp::max, num::NonZeroU16}; use crate::{ - app::AppConfigFields, + app::{data::TypedTemperature, AppConfigFields}, canvas::components::data_table::{ ColumnHeader, DataTableColumn, DataTableProps, DataTableStyling, DataToCell, SortColumn, SortDataTable, SortDataTableProps, SortOrder, SortsRow, }, - collection::temperature::RoundedTypedTemperature, options::config::style::Styles, utils::general::sort_partial_fn, }; @@ -14,7 +13,7 @@ use crate::{ #[derive(Clone, Debug)] pub struct TempWidgetData { pub sensor: String, - pub temperature: Option, + pub temperature: Option, } pub enum TempWidgetColumn {