diff --git a/bin/sensors.rs b/bin/sensors.rs index 64537ee..570fa0a 100644 --- a/bin/sensors.rs +++ b/bin/sensors.rs @@ -7,10 +7,10 @@ use sysinfo::{ComponentExt, RefreshKind, System, SystemExt}; /// /// Each line contains a sensor and its temperature, in the following format: /// -/// TEMP:LABEL +/// TEMP:COMPONENT /// -/// Where TEMP is the temperature in Celsius, and LABEL is the name of the sensor. -/// The LABEL property can by used to configure bar items with type "sensors". +/// Where TEMP is the temperature in Celsius, and COMPONENT is the name of the sensor. +/// The COMPONENT property can by used to configure bar items with type "sensors". struct Cli; fn main() { diff --git a/sample_config.toml b/sample_config.toml index 71e5bbb..cc07e49 100644 --- a/sample_config.toml +++ b/sample_config.toml @@ -184,7 +184,9 @@ name = "cpu-temp" interval = "5s" # The name of the component to display temperature for. # The `i3stat-sensors` command is provided and outputs a list of components that can be used. -label = "coretemp Package id 0" +component = "coretemp Package id 0" +# Optional: set a label to be shown in the item (useful if you have multiple sensor items) +label = " (cpu)" # See: FLOAT FORMAT OPTIONS pad = ' ' pad_count = 2 diff --git a/src/bar_items/sensors.rs b/src/bar_items/sensors.rs index e9d3df4..b12b328 100644 --- a/src/bar_items/sensors.rs +++ b/src/bar_items/sensors.rs @@ -16,7 +16,9 @@ use crate::util::format::{float, FloatFormat}; pub struct Sensors { #[serde(with = "crate::human_time")] interval: Duration, - label: String, + #[serde(default)] + label: Option, + component: String, #[serde(flatten)] float_fmt: FloatFormat, } @@ -40,10 +42,11 @@ impl BarItem for Sensors { ctx.state.sys.refresh_components_list(); } + let label = self.label.as_deref().unwrap_or(""); loop { let temp = { let search = ctx.state.sys.components_mut().iter_mut().find_map(|c| { - if c.label() == self.label { + if c.label() == self.component { c.refresh(); Some(c.temperature()) } else { @@ -54,14 +57,16 @@ impl BarItem for Sensors { match search { Some(temp) => temp, None => { - break Err(format!("no component found with label: {}", self.label).into()) + break Err( + format!("no component found with name: {}", self.component).into() + ) } } }; let (icon, color) = Self::get_icon(&ctx.config.theme, temp as u32); let temp = float(temp, &self.float_fmt); - let mut item = I3Item::new(format!("{} {}°C", icon, temp)) + let mut item = I3Item::new(format!("{} {}°C{}", icon, temp, label)) .short_text(format!("{}C", temp)) .markup(I3Markup::Pango); diff --git a/tests/i3/screenshots.rs b/tests/i3/screenshots.rs index faafe98..d6605be 100644 --- a/tests/i3/screenshots.rs +++ b/tests/i3/screenshots.rs @@ -470,7 +470,7 @@ screenshot!( json!({ "type": "sensors", "interval": "1s", - "label": "name temp1" + "component": "name temp1" }), { at_0: {