mirror of
https://github.com/Atsukoro1/ponyfetch.git
synced 2024-11-23 20:57:59 +01:00
feat: 🎸 Uptime
This commit is contained in:
parent
d27ab9a917
commit
e0a139151f
3 changed files with 18 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
mod system;
|
||||
|
||||
fn main() {
|
||||
println!("{}", system::specs::get_ram_used())
|
||||
println!("{}", system::host::get_uptime())
|
||||
}
|
||||
|
|
|
@ -58,3 +58,20 @@ pub fn get_distro() -> String {
|
|||
|
||||
distro.to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn get_uptime() -> String {
|
||||
let mut temp_buf: String = String::new();
|
||||
|
||||
let mut file = File::open("/proc/uptime").unwrap();
|
||||
file.read_to_string(&mut temp_buf).unwrap();
|
||||
|
||||
let uptime: u128 = temp_buf.split(".").collect::<Vec<&str>>()[0].parse().unwrap();
|
||||
|
||||
let days = uptime / 86400;
|
||||
let hours = (uptime % 86400) / 3600;
|
||||
let minutes = (uptime % 3600) / 60;
|
||||
let seconds = uptime % 60;
|
||||
|
||||
format!("{}d {}h {}m {}s", days, hours, minutes, seconds)
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::ops::Add;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
Loading…
Reference in a new issue