Finishing touches
This commit is contained in:
parent
fa044a4548
commit
275bab9c6b
82
src/main.rs
82
src/main.rs
@ -1,26 +1,34 @@
|
||||
|
||||
use std::fmt;
|
||||
use chrono::*;
|
||||
use colored::*;
|
||||
use sysinfo::*;
|
||||
use whoami::*;
|
||||
use chrono::*;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
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("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("Uptime", '', &format!("{}s", sys_info.uptime), "bright black");
|
||||
color_print("Shell", '', &sys_info.shell, "bright magenta");
|
||||
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));
|
||||
println!(
|
||||
"{}: {}",
|
||||
field_title.bright_white(),
|
||||
format!("{} {}", icon, field).color(color)
|
||||
);
|
||||
}
|
||||
|
||||
struct InformationStruct {
|
||||
@ -31,10 +39,10 @@ struct InformationStruct {
|
||||
kernel_ver: String,
|
||||
uptime: u64,
|
||||
shell: String,
|
||||
terminal: String,
|
||||
_terminal: String,
|
||||
cpu: String,
|
||||
gpu: String,
|
||||
memory: String,
|
||||
_gpu: String,
|
||||
_memory: String,
|
||||
icon: char,
|
||||
color: String,
|
||||
}
|
||||
@ -43,19 +51,45 @@ impl InformationStruct {
|
||||
fn new() -> Self {
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_all();
|
||||
Self{
|
||||
Self {
|
||||
username: whoami::username(),
|
||||
|
||||
hostname: whoami::hostname(),
|
||||
|
||||
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(),
|
||||
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()),
|
||||
gpu: String::from("Unknown GPU"),
|
||||
memory: String::from("Unknown memory"),
|
||||
icon: match sys.name().unwrap_or(String::from("Unknown System")).as_ref() {
|
||||
|
||||
_gpu: String::from("Unknown GPU"), // TODO: Add GPU detection.
|
||||
|
||||
_memory: String::from("Unknown memory"), // TODO: Add memory detection.
|
||||
|
||||
icon: match sys
|
||||
.name()
|
||||
.unwrap_or(String::from("Unknown System"))
|
||||
.as_ref()
|
||||
{
|
||||
"Alma Linux" => '',
|
||||
"Alpine Linux" => '',
|
||||
"Arch Linux" => '',
|
||||
@ -79,9 +113,14 @@ impl InformationStruct {
|
||||
"Unknown System" => '?',
|
||||
_ => {
|
||||
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"),
|
||||
"FreeBSD" => String::from("red"),
|
||||
"Ubuntu Linux" => String::from("orange"),
|
||||
@ -95,5 +134,4 @@ impl InformationStruct {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user