added more system info

This commit is contained in:
FantasyPvP
2024-10-16 00:31:25 +01:00
parent 5e9d5f5c3b
commit d73d80ca8d
3 changed files with 68 additions and 36 deletions
Generated
+11
View File
@@ -193,6 +193,16 @@ version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "users"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
dependencies = [
"libc",
"log",
]
[[package]] [[package]]
name = "wasite" name = "wasite"
version = "0.1.0" version = "0.1.0"
@@ -486,5 +496,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"colored", "colored",
"sysinfo", "sysinfo",
"users",
"whoami", "whoami",
] ]
+1
View File
@@ -6,4 +6,5 @@ edition = "2021"
[dependencies] [dependencies]
colored = "2.1.0" colored = "2.1.0"
sysinfo = "0.32.0" sysinfo = "0.32.0"
users = "0.11.0"
whoami = "1.5.2" whoami = "1.5.2"
+41 -21
View File
@@ -1,5 +1,7 @@
use std::process::Command; use std::process::Command;
use sysinfo::{Components, Disks, Networks, System}; use sysinfo::{Components, Disks, Networks, System};
use colored::*;
use users::{get_user_by_uid, get_current_uid};
static LOGO: &str = "       'xkXxdxddd,oddc. .  'c:      static LOGO: &str = "       'xkXxdxddd,oddc. .  'c:     
     MM0d' :kk' 'ldddx0OkMMMMMMXOxdxKk.        MM0d' :kk' 'ldddx0OkMMMMMMXOxdxKk.  
@@ -22,30 +24,43 @@ static LOGO: &str = "     [38
 cMMM .XKXMM.  ..,   ";  cMMM .XKXMM.  ..,   ";
fn main() { fn main() {
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);
let mut sys = System::new_all(); let mut sys = System::new_all();
sys.refresh_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![ let info = vec![
String::new(), format!(""),
String::new(), format!("┌────────────"),
format!("OS Name : {}", System::name().unwrap()), //format!("│ {} : {}", "Username ".to_string().truecolor(90, 100, 255), user.name().to_str().unwrap().to_string()),
format!("Kernel : {}", System::kernel_version().unwrap()), format!("{} : {}", "OS Name ".to_string().truecolor(90, 100, 255), System::name().unwrap()),
format!("OS Version : {}", System::os_version().unwrap()), format!("{} : {}", "Kernel ".to_string().truecolor(90, 100, 255), System::kernel_version().unwrap()),
format!("Hostname : {}", System::host_name().unwrap()), format!("{} : {}", "OS Version".to_string().truecolor(90, 100, 255), System::os_version().unwrap()),
format!("CPU Arch : {}", System::cpu_arch().unwrap()), format!("{} : {}", "Hostname ".to_string().truecolor(90, 100, 255), System::host_name().unwrap()),
format!( format!("{} : {}", "CPU Arch ".to_string().truecolor(90, 100, 255), System::cpu_arch().unwrap()),
"CPU Cores : {}", format!("{} : {}", "CPU Cores ".to_string().truecolor(90, 100, 255),
sys.physical_core_count().unwrap().to_string() sys.physical_core_count().unwrap().to_string()
), ),
format!( format!("{} : {}", "Shell ".to_string().truecolor(90, 100, 255), parent_name),
"Uptime : {}", 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(); let u_s = System::uptime();
format!( format!(
"{} Hours {} Minutes {} Seconds", "{} Hours {} Minutes {} Seconds",
@@ -53,15 +68,20 @@ fn main() {
u_s % 3600 / 60, u_s % 3600 / 60,
u_s % 60 u_s % 60
) )
})() })()),
),
format!( format!(
"Memory Use : {}MiB / {}MiB", "{} : {}MiB / {}MiB", "Memory Use".to_string().truecolor(90, 100, 255),
sys.used_memory() / 1000000, sys.used_memory() / 1000000,
sys.total_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"); println!("\n");
let binding = String::new(); let binding = String::new();