mirror of
https://github.com/Wojtek242/rwmstatus.git
synced 2024-11-21 23:25:26 +01:00
Fixes for GitHub Issue #1
This commit is contained in:
parent
a6d36906a8
commit
ce2fe133d5
28
src/lib.rs
28
src/lib.rs
@ -125,20 +125,16 @@ impl RwmStatus {
|
|||||||
Err(_) => return vec![],
|
Err(_) => return vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let dir_filtered = dir.filter(|path_result| match path_result {
|
let dir_contents = dir.filter_map(|path_result| {
|
||||||
Ok(path) => {
|
path_result.ok().and_then(|path| Some(path.path()))
|
||||||
match path.file_name().to_str() {
|
|
||||||
Some(entry) => entry.starts_with(prefix),
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut paths: Vec<PathBuf> = dir_filtered
|
let mut paths: Vec<PathBuf> = dir_contents
|
||||||
.map(|path_result| match path_result {
|
.filter(|path| {
|
||||||
Ok(path) => path.path(),
|
path.file_name()
|
||||||
Err(_) => panic!("Unexpected file path"),
|
.and_then(|os_str| os_str.to_str())
|
||||||
|
.filter(|entry| entry.starts_with(prefix))
|
||||||
|
.is_some()
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -154,7 +150,7 @@ impl RwmStatus {
|
|||||||
|
|
||||||
let temp_strs: Vec<String> = self.hw_mons
|
let temp_strs: Vec<String> = self.hw_mons
|
||||||
.iter()
|
.iter()
|
||||||
.map(|hw_mon| get_temp(&hw_mon).unwrap_or("".into()))
|
.map(|hw_mon| get_temp(&hw_mon).unwrap_or_else(|_| "".into()))
|
||||||
.collect();
|
.collect();
|
||||||
Some(temp_strs.join("|"))
|
Some(temp_strs.join("|"))
|
||||||
}
|
}
|
||||||
@ -162,7 +158,7 @@ impl RwmStatus {
|
|||||||
/// Return the three load average values.
|
/// Return the three load average values.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_load_avgs(&self) -> String {
|
pub fn get_load_avgs(&self) -> String {
|
||||||
get_load_avgs().unwrap_or(format!(""))
|
get_load_avgs().unwrap_or_else(|_| "".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return battery status for all batteries.
|
/// Return battery status for all batteries.
|
||||||
@ -173,7 +169,7 @@ impl RwmStatus {
|
|||||||
|
|
||||||
let batt_strs: Vec<String> = self.batts
|
let batt_strs: Vec<String> = self.batts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|batt| get_batt(&batt).unwrap_or("".into()))
|
.map(|batt| get_batt(&batt).unwrap_or_else(|_| "".into()))
|
||||||
.collect();
|
.collect();
|
||||||
Some(batt_strs.join("|"))
|
Some(batt_strs.join("|"))
|
||||||
}
|
}
|
||||||
@ -186,7 +182,7 @@ impl RwmStatus {
|
|||||||
format!(
|
format!(
|
||||||
"{}:{}",
|
"{}:{}",
|
||||||
tz.label,
|
tz.label,
|
||||||
get_tz_time(&tz.name, "%H:%M").unwrap_or("".into())
|
get_tz_time(&tz.name, "%H:%M").unwrap_or_else(|_| "".into())
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -39,9 +39,8 @@ fn main() {
|
|||||||
|
|
||||||
let rwmstatus = RwmStatus::new(config::HW_MON_PATH, config::BATT_PATH, &config::TZS[..]);
|
let rwmstatus = RwmStatus::new(config::HW_MON_PATH, config::BATT_PATH, &config::TZS[..]);
|
||||||
|
|
||||||
|
let mut stats = vec![];
|
||||||
loop {
|
loop {
|
||||||
let mut stats = vec![];
|
|
||||||
|
|
||||||
if let Some(temps) = rwmstatus.get_temperatures() {
|
if let Some(temps) = rwmstatus.get_temperatures() {
|
||||||
stats.push(format!("T:{}", temps));
|
stats.push(format!("T:{}", temps));
|
||||||
}
|
}
|
||||||
@ -63,5 +62,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(60));
|
std::thread::sleep(std::time::Duration::from_secs(60));
|
||||||
|
|
||||||
|
stats.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user