First commit

This commit is contained in:
Andrew Schott 2025-06-13 01:10:08 -05:00
commit 20ce0359e0
6 changed files with 331 additions and 0 deletions

81
src/main.rs Normal file
View file

@ -0,0 +1,81 @@
use sysinfo::{Disks, System};
use colored::Colorize;
use std::process::Command;
fn main() {
let mut sys = System::new_all();
sys.refresh_all();
// RAM Information
println!("{}", "* RAM Information:".bold());
let total_memory = sys.total_memory() as f64 / 1024.0 / 1024.0 / 1024.0;
println!("RAM in GB\t\t{:.2}", total_memory);
println!();
// CPU Information
println!("{}", "* CPU Information:".bold());
let cpu_cores = sys.physical_core_count().unwrap_or(0);
let cpu_threads = sys.cpus().len();
println!("CPU Cores\t{}", cpu_cores);
println!("CPU Threads\t{}", cpu_threads);
println!();
// Disk Information
println!("{}", "* Disk Information:".bold());
println!("(Device - Size - Used - Free - % - Mountpoint)");
let disks = Disks::new_with_refreshed_list();
for disk in disks.iter() {
let name = disk.name().to_string_lossy();
if name.contains("nvme") || name.contains("/dev/sd") || name.contains("/dev/mapper") {
let total_space = disk.total_space() as f64 / 1_000_000_000.0;
let available_space = disk.available_space() as f64 / 1_000_000_000.0;
let used_space = total_space - available_space;
let percent = if total_space > 0.0 { (used_space / total_space) * 100.0 } else { 0.0 };
println!(
"{} - {:.1}GB - {:.1}GB - {:.1}GB - {:.1}% - {}",
name,
total_space,
used_space,
available_space,
percent,
disk.mount_point().display()
);
}
}
println!();
// Wifi Information
println!("{}", "* Wifi Information:".bold());
if let Ok(output) = Command::new("nmcli").args(&["dev", "status"]).output() {
let output_str = String::from_utf8_lossy(&output.stdout);
for line in output_str.lines() {
if line.contains("connected") && !line.contains("disconnected") {
println!("{}", line);
}
}
} else {
println!("Unable to retrieve wifi information (nmcli not available)");
}
println!();
// Window Manager
println!("{}", "* Window Manager".bold());
if let Ok(desktop) = std::env::var("DESKTOP_SESSION") {
println!("{}", desktop);
} else {
println!("Unknown");
}
println!();
// Current Shell
println!("{}", "* Current Shell".bold());
if let Ok(shell) = std::env::var("SHELL") {
println!("{}", shell);
} else {
println!("Unknown");
}
println!();
println!("To pipe this output to a file, run the program as follows:");
println!("{}", "\thardware-info >> ./hardware-info.log".bold());
}