diff --git a/src/system_values.rs b/src/system_values.rs index 647c490..b117c6b 100644 --- a/src/system_values.rs +++ b/src/system_values.rs @@ -1,19 +1,14 @@ -use std::{ - env, - process::Command, -}; +use std::{env, process::Command}; pub fn get_temperature() -> f32 { - let mut temperature = 0.0; let system = env::var("SYSTEM").unwrap().to_string(); if system == "ubuntu" { let temperature_command = Command::new("cat") .arg("/sys/class/thermal/thermal_zone1/temp") - .output().unwrap_or_else(|e| { - panic!("failed to execute process: {}", e) - }); + .output() + .unwrap_or_else(|e| panic!("failed to execute process: {}", e)); let temperature_string = &String::from_utf8_lossy(&temperature_command.stdout)[..5]; temperature = temperature_string.parse::().unwrap(); @@ -22,9 +17,8 @@ pub fn get_temperature() -> f32 { let temperature_command = Command::new("sudo") .arg("/opt/vc/bin/vcgencmd") .arg("measure_temp") - .output().unwrap_or_else(|e| { - panic!("failed to execute process: {}", e) - }); + .output() + .unwrap_or_else(|e| panic!("failed to execute process: {}", e)); let mut temperature_string = &String::from_utf8_lossy(&temperature_command.stdout)[5..]; temperature_string = &temperature_string[..temperature_string.len() - 3]; @@ -38,28 +32,28 @@ pub fn get_storage() -> i8 { let storage_command = Command::new("df") .arg("-h") .arg("/") - .output().unwrap_or_else(|e| { - panic!("failed to execute process: {}", e) - }); + .output() + .unwrap_or_else(|e| panic!("failed to execute process: {}", e)); let storage_string = &String::from_utf8_lossy(&storage_command.stdout); - let vec_storage : Vec<&str> = storage_string.split_whitespace().collect(); - let storage = (vec_storage[vec_storage.len() - 2][..2]).parse::().unwrap(); + let vec_storage: Vec<&str> = storage_string.split_whitespace().collect(); + let mut value = vec_storage[vec_storage.len() - 2].to_string(); + value.pop(); + let storage = value.parse::().unwrap(); return storage; } pub fn get_mem() -> i8 { let mem_command = Command::new("free") - .arg("-m") - .output().unwrap_or_else(|e| { - panic!("failed to execute process: {}", e) - }); + .arg("-m") + .output() + .unwrap_or_else(|e| panic!("failed to execute process: {}", e)); let mem_string = &String::from_utf8_lossy(&mem_command.stdout); - let vec_mem : Vec<&str> = mem_string.split_whitespace().collect(); - let total = vec_mem[7].parse::().unwrap(); - let mem_use = vec_mem[8].parse::().unwrap(); + let vec_mem: Vec<&str> = mem_string.split_whitespace().collect(); + let total = vec_mem[7].parse::().unwrap(); + let mem_use = vec_mem[8].parse::().unwrap(); let result = (mem_use / total * 100.0) as i8; return result; @@ -71,13 +65,14 @@ pub fn get_battery() -> i8 { if system == "ubuntu" { let battery_command = Command::new("cat") - .arg("/sys/class/power_supply/BAT0/capacity") - .output().unwrap_or_else(|e| { - panic!("failed to execute process: {}", e) - }); + .arg("/sys/class/power_supply/BAT0/capacity") + .output() + .unwrap_or_else(|e| panic!("failed to execute process: {}", e)); let battery_string = &String::from_utf8_lossy(&battery_command.stdout); - battery = (&battery_string[..battery_string.len() - 1]).parse::().unwrap(); + battery = (&battery_string[..battery_string.len() - 1]) + .parse::() + .unwrap(); } return battery;