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"
+56 -36
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,46 +24,64 @@ static LOGO: &str = "     [38
 cMMM .XKXMM.  ..,   ";  cMMM .XKXMM.  ..,   ";
fn main() { fn main() {
let info_kernel_out = Command::new("uname") 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") .arg("-r")
.output() .output()
.expect("failed to fetch kernel ver"); .expect("failed to fetch kernel ver");
let info_kernel = String::from_utf8_lossy(&info_kernel_out.stdout); let info_kernel = String::from_utf8_lossy(&info_kernel_out.stdout);
let mut sys = System::new_all();
sys.refresh_all();
let info = vec![
String::new(),
String::new(),
format!("OS Name : {}", System::name().unwrap()),
format!("Kernel : {}", System::kernel_version().unwrap()),
format!("OS Version : {}", System::os_version().unwrap()),
format!("Hostname : {}", System::host_name().unwrap()),
format!("CPU Arch : {}", System::cpu_arch().unwrap()),
format!(
"CPU Cores : {}",
sys.physical_core_count().unwrap().to_string()
),
format!(
"Uptime : {}",
(|| {
let u_s = System::uptime();
format!(
"{} Hours {} Minutes {} Seconds",
u_s / 3600,
u_s % 3600 / 60,
u_s % 60
)
})()
),
format!(
"Memory Use : {}MiB / {}MiB",
sys.used_memory() / 1000000,
sys.total_memory() / 1000000
),
];
println!("\n"); println!("\n");
let binding = String::new(); let binding = String::new();