back in working state with nicer code lol

This commit is contained in:
River 2023-01-04 17:09:46 -05:00
parent ddb3c9b291
commit fa044a4548

View File

@ -1,3 +1,5 @@
use std::fmt;
use colored::*; use colored::*;
use sysinfo::*; use sysinfo::*;
use whoami::*; use whoami::*;
@ -5,7 +7,20 @@ use chrono::*;
fn main() { fn main() {
let sys_info = InformationStruct::new(); let sys_info = InformationStruct::new();
println!("{}", sys_info.os_name); let datetime_formatted = format!("{}, {}", Utc::now().weekday(), Utc::now().format("%H:%M %Y-%m-%d"));
color_print("Date", '', &datetime_formatted, "bright yellow");
color_print("Host", '', &format!("{}@{}", sys_info.username, sys_info.hostname), "purple");
color_print("OS", sys_info.icon, &sys_info.os_name, &sys_info.color);
color_print("Version", '', &sys_info.os_ver, "red");
color_print("Kernel", '', &sys_info.kernel_ver, "bright blue");
color_print("Uptime", '', &format!("{}s", sys_info.uptime), "bright black");
color_print("CPU", '', &sys_info.cpu, "green");
}
fn color_print(field_title: &str, icon: char, field: &str, color: &str) {
println!("{}: {}", field_title.bright_white(), format!("{} {}", icon, field).color(color));
} }
struct InformationStruct { struct InformationStruct {
@ -21,6 +36,7 @@ struct InformationStruct {
gpu: String, gpu: String,
memory: String, memory: String,
icon: char, icon: char,
color: String,
} }
impl InformationStruct { impl InformationStruct {
@ -39,7 +55,45 @@ impl InformationStruct {
cpu: String::from(sys.cpus()[0].brand()), cpu: String::from(sys.cpus()[0].brand()),
gpu: String::from("Unknown GPU"), gpu: String::from("Unknown GPU"),
memory: String::from("Unknown memory"), memory: String::from("Unknown memory"),
icon: '?', icon: match sys.name().unwrap_or(String::from("Unknown System")).as_ref() {
"Alma Linux" => '',
"Alpine Linux" => '',
"Arch Linux" => '',
"CentOS" => '',
"Linux Debian" => '',
"ElementaryOS" => '',
"EndeavourOS" => '',
"Fedora Linux" => '',
"FreeBSD" => '',
"Gentoo Linux" => '',
"Kali Linux" => '',
"Linux Mint" => '',
"Manjaro Linux" => '',
"OpenSUSE" => '',
"PopOS" => '',
"Ubuntu Linux" => '',
"Windows" => '',
"Android" => '',
"iOS" => '',
"macOS" => '',
"Unknown System" => '?',
_ => {
unreachable!()
},
},
color: match sys.name().unwrap_or(String::from("Unknown System")).as_ref() {
"Linux Debian" => String::from("bright red"),
"FreeBSD" => String::from("red"),
"Ubuntu Linux" => String::from("orange"),
"Arch Linux" | "Windows" | "PopOS" => String::from("bright cyan"),
"Fedora Linux" | "Kali Linux" => String::from("bright blue"),
"OpenSUSE" | "Linux Mint" | "Android" => String::from("bright green"),
"EndeavourOS" | "Gentoo linux" => String::from("purple"),
"iOS" | "macOS" | "ElementaryOS" => String::from("bright white"),
_ => String::from("bright white"),
},
} }
} }
} }