use std::process::Command; use sysinfo::{Components, Disks, Networks, System}; use colored::*; use users::{get_user_by_uid, get_current_uid}; static LOGO: &str = "       'xkXxdxddd,oddc. .  'c:           MM0d' :kk' 'ldddx0OkMMMMMMXOxdxKk.         NO;oo.  .co;;:cxMMMMMMMMMMMMMMMMM       dxc;dxccco:l,''....XMMMMM',xK0lkMM     'dX:cMMMll;MMMMMMMMMMMkk: ..::oXx   .MlcMM0 M0  co: ....     xM WMM'oM,  ;oooxMM     Oo.MMM MM        lXNMMWocKMMMMMMMMMMMMMMMMMMMd    .co0MMM0:codMMMMKMWdddoMMMMMM..    .od0MMMM:  OMMMxN:  olc:;.       ::;:::xX: lMMMMKdd..... ,ll   .:. cc   OlkWkddddol:.',;:.. .    . ;d  :oo .odd: lddddd  ..   .;  d,. 'd dol:;. .',    :,   . c: .':    dKd'do ..    ';c      MM0ddd;dkx'  .,c     cMMM .XKXMM.  ..,   "; fn main() { let mut sys = System::new_all(); sys.refresh_all(); let user = get_user_by_uid(get_current_uid()).unwrap(); let shell = String::from_utf8( Command::new("bash").arg("-c").arg("echo $SHELL").output().expect("failed to exec").stdout ).unwrap().split("/").last().unwrap().trim().to_string(); let term = String::from_utf8( Command::new("bash").arg("-c").arg("echo $TERM").output().expect("failed to exec").stdout ).unwrap().trim().to_string(); let de = String::from_utf8( Command::new("bash").arg("-c").arg("echo $XDG_CURRENT_DESKTOP").output().expect("failed to exec").stdout ).unwrap().trim().to_string(); let my_pid = sysinfo::get_current_pid().expect("unable to get PID of the current process"); let parent_pid = sys.process(my_pid).expect("no self process?").parent().expect("unable to get parent process"); let parent_name = sys.process(parent_pid).expect("unable to get parent process").name().to_str().unwrap().to_string(); let info = vec![ format!(""), format!("┌────────────"), //format!("│ {} : {}", "Username ".to_string().truecolor(90, 100, 255), user.name().to_str().unwrap().to_string()), format!("│ {} : {}", "OS Name ".to_string().truecolor(90, 100, 255), System::name().unwrap()), format!("│ {} : {}", "Kernel ".to_string().truecolor(90, 100, 255), System::kernel_version().unwrap()), format!("│ {} : {}", "OS Version".to_string().truecolor(90, 100, 255), System::os_version().unwrap()), format!("│ {} : {}", "Hostname ".to_string().truecolor(90, 100, 255), System::host_name().unwrap()), format!("│ {} : {}", "CPU Arch ".to_string().truecolor(90, 100, 255), System::cpu_arch().unwrap()), format!("│ {} : {}", "CPU Cores ".to_string().truecolor(90, 100, 255), sys.physical_core_count().unwrap().to_string() ), format!("│ {} : {}", "Shell ".to_string().truecolor(90, 100, 255), parent_name), format!("│ {} : {}", "Terminal ".to_string().truecolor(90, 100, 255), term), format!("│ {} : {}", "Desktop ".to_string().truecolor(90, 100, 255), de), format!("│ {} : {}", "Uptime ".to_string().truecolor(90, 100, 255), (|| { let u_s = System::uptime(); format!( "{} Hours {} Minutes {} Seconds", u_s / 3600, u_s % 3600 / 60, u_s % 60 ) })()), format!( "│ {} : {}MiB / {}MiB", "Memory Use".to_string().truecolor(90, 100, 255), sys.used_memory() / 1000000, sys.total_memory() / 1000000 ), format!("└────────────") ]; let info_kernel_out = Command::new("uname") .arg("-r") .output() .expect("failed to fetch kernel ver"); let info_kernel = String::from_utf8_lossy(&info_kernel_out.stdout); println!("\n"); let binding = String::new(); let mut iter = LOGO .lines() .zip(info.iter().chain(std::iter::repeat(&binding))); while let Some((logo, info)) = iter.next() { println!("{} {}", logo, info); } }