mod battery; mod tp_battery; mod disk; mod netspeed; mod time; mod temperature; use config::Config; use self::battery::BatterySensor; use self::tp_battery::TPBatterySensor; use self::disk::DiskSensor; use self::netspeed::NetSpeedSensor; use self::temperature::TempSensor; use self::time::TimeSensor; pub trait Sensor { fn icon(&self) -> String; fn status(&self) -> String; fn process(&mut self); } pub fn sensor_list(config: &Config) -> Vec> { let zone = config.lookup("sensors.thermal_zone").unwrap(); let zone = zone.as_str().unwrap(); let devices = config.lookup("netspeed.devices").unwrap(); let devices = devices.as_slice().unwrap(); let devices: Vec<&str> = devices.iter().flat_map(|elem| elem.as_str()).collect(); let mut sensors: Vec> = vec![ Box::new(NetSpeedSensor::new(&devices)), Box::new(DiskSensor::new("/")), Box::new(TempSensor::new(zone)), Box::new(TimeSensor::new("%H:%M", true)), Box::new(TimeSensor::new("%a, %Y-%m-%d %H:%M", false)) ]; let bat = config.lookup("sensors.battery"); let bat = bat.map(|bat| bat.as_str().unwrap()); bat.map(|bat| sensors.insert(1, Box::new(BatterySensor::new(bat)))); let tp_bat = config.lookup("sensors.tp_battery"); let tp_bat = tp_bat.map(|tp_bat| { let items = tp_bat.as_slice().unwrap(); items.iter().flat_map(|elem| elem.as_str()).collect::>() }); tp_bat.map(|bats| sensors.insert(1, Box::new(TPBatterySensor::new(&bats)))); sensors }