aboutsummaryrefslogtreecommitdiff
path: root/src/utils/load_average.rs
blob: 2cd271f1f1bef4192567c59871bfbe3487b7f2e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::types::Config;
use std::fs::File;
use std::io::Read;

pub fn get_load_avg(config: &Config) -> 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)
}