aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/load_average.rs16
-rw-r--r--src/utils/mod.rs1
2 files changed, 17 insertions, 0 deletions
diff --git a/src/utils/load_average.rs b/src/utils/load_average.rs
new file mode 100644
index 0000000..2cd271f
--- /dev/null
+++ b/src/utils/load_average.rs
@@ -0,0 +1,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)
+}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index b497999..6834d49 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -1,6 +1,7 @@
pub mod battery;
pub mod cpu;
pub mod disk;
+pub mod load_average;
pub mod memory;
pub mod mpd;
pub mod spotify;