Finishing touches

This commit is contained in:
River 2023-01-04 17:57:55 -05:00
parent fa044a4548
commit 275bab9c6b

View File

@ -1,26 +1,34 @@
use chrono::*;
use std::fmt;
use colored::*; use colored::*;
use sysinfo::*; use sysinfo::*;
use whoami::*; use std::env;
use chrono::*;
fn main() { fn main() {
let sys_info = InformationStruct::new(); let sys_info = InformationStruct::new();
let datetime_formatted = format!("{}, {}", Utc::now().weekday(), Utc::now().format("%H:%M %Y-%m-%d")); let datetime_formatted = format!(
"{}, {}",
Utc::now().weekday(),
Utc::now().format("%H:%M %Y-%m-%d")
);
println!();
color_print("Date", '', &datetime_formatted, "bright yellow"); color_print("Date", '', &datetime_formatted, "bright yellow");
color_print("Host", '', &format!("{}@{}", sys_info.username, sys_info.hostname), "purple"); 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("OS", sys_info.icon, &sys_info.os_name, &sys_info.color);
color_print("Version", '', &sys_info.os_ver, "red"); color_print("Version", '', &sys_info.os_ver, "red");
color_print("Kernel", '', &sys_info.kernel_ver, "bright blue"); color_print("Kernel", '', &sys_info.kernel_ver, "bright blue");
color_print("Uptime", '', &format!("{}s", sys_info.uptime), "bright black"); color_print("Uptime", '', &format!("{}s", sys_info.uptime), "bright black");
color_print("Shell", '', &sys_info.shell, "bright magenta");
color_print("CPU", '', &sys_info.cpu, "green"); color_print("CPU", '', &sys_info.cpu, "green");
} }
fn color_print(field_title: &str, icon: char, field: &str, color: &str) { fn color_print(field_title: &str, icon: char, field: &str, color: &str) {
println!("{}: {}", field_title.bright_white(), format!("{} {}", icon, field).color(color)); println!(
"{}: {}",
field_title.bright_white(),
format!("{} {}", icon, field).color(color)
);
} }
struct InformationStruct { struct InformationStruct {
@ -31,10 +39,10 @@ struct InformationStruct {
kernel_ver: String, kernel_ver: String,
uptime: u64, uptime: u64,
shell: String, shell: String,
terminal: String, _terminal: String,
cpu: String, cpu: String,
gpu: String, _gpu: String,
memory: String, _memory: String,
icon: char, icon: char,
color: String, color: String,
} }
@ -43,19 +51,45 @@ impl InformationStruct {
fn new() -> Self { fn new() -> Self {
let mut sys = System::new_all(); let mut sys = System::new_all();
sys.refresh_all(); sys.refresh_all();
Self{ Self {
username: whoami::username(), username: whoami::username(),
hostname: whoami::hostname(), hostname: whoami::hostname(),
os_name: sys.name().unwrap_or(String::from("Unknown System")), os_name: sys.name().unwrap_or(String::from("Unknown System")),
os_ver: sys.os_version().unwrap_or(String::from("Unknown System Version")),
kernel_ver: sys.kernel_version().unwrap_or(String::from("Unknown Kernel Version")), os_ver: sys
.os_version()
.unwrap_or(String::from("Unknown System Version")),
kernel_ver: sys
.kernel_version()
.unwrap_or(String::from("Unknown Kernel Version")),
uptime: sys.uptime(), uptime: sys.uptime(),
shell: String::from("Unknown Shell"),
terminal: String::from("Unknown Terminal"), shell: {
let var = env::var("SHELL");
if var.is_ok() {
format!("{}", var.unwrap().split('/').last().unwrap())
} else {
String::from("Unknown Shell")
}
},
_terminal: String::from("Unknown Terminal"), // TODO: Add terminal detection.
cpu: String::from(sys.cpus()[0].brand()), cpu: String::from(sys.cpus()[0].brand()),
gpu: String::from("Unknown GPU"),
memory: String::from("Unknown memory"), _gpu: String::from("Unknown GPU"), // TODO: Add GPU detection.
icon: match sys.name().unwrap_or(String::from("Unknown System")).as_ref() {
_memory: String::from("Unknown memory"), // TODO: Add memory detection.
icon: match sys
.name()
.unwrap_or(String::from("Unknown System"))
.as_ref()
{
"Alma Linux" => '', "Alma Linux" => '',
"Alpine Linux" => '', "Alpine Linux" => '',
"Arch Linux" => '', "Arch Linux" => '',
@ -79,9 +113,14 @@ impl InformationStruct {
"Unknown System" => '?', "Unknown System" => '?',
_ => { _ => {
unreachable!() unreachable!()
}, }
}, },
color: match sys.name().unwrap_or(String::from("Unknown System")).as_ref() {
color: match sys
.name()
.unwrap_or(String::from("Unknown System"))
.as_ref()
{
"Linux Debian" => String::from("bright red"), "Linux Debian" => String::from("bright red"),
"FreeBSD" => String::from("red"), "FreeBSD" => String::from("red"),
"Ubuntu Linux" => String::from("orange"), "Ubuntu Linux" => String::from("orange"),
@ -95,5 +134,4 @@ impl InformationStruct {
}, },
} }
} }
}
}