rsblocks/src/utils/load_average.rs
AdaShoelace 861a986567 Change to serde
Change config serializer to serde in order to get cleaner config types.
2021-01-21 22:24:15 +01:00

17 lines
503 B
Rust

use crate::config::CONFIG;
use std::fs::File;
use std::io::Read;
pub fn get_load_avg() -> String {
let mut buf = String::new();
match File::open("/proc/loadavg") {
Ok(mut file) => match file.read_to_string(&mut buf) {
Ok(data) => data,
_ => return String::from(""),
},
_ => return String::from("Error"),
};
let buf = buf.split_whitespace().collect::<Vec<_>>()[0];
format!(" {} {} {}", CONFIG.loadavg.icon, buf, CONFIG.seperator)
}