2024-03-23 21:58:32 +00:00
|
|
|
use colored::Colorize;
|
2024-03-24 14:08:46 +00:00
|
|
|
use std::env::var;
|
2024-03-23 22:35:06 +00:00
|
|
|
use sysinfo::System;
|
|
|
|
use whoami::*;
|
2024-03-24 14:08:46 +00:00
|
|
|
use clap::Parser;
|
2024-03-24 12:48:11 +00:00
|
|
|
|
|
|
|
/// A simple and adorable sysinfo utility written in Rust.
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
#[command(version, about, long_about = None)]
|
|
|
|
struct Args {
|
|
|
|
/// Show ASCII art only
|
|
|
|
#[arg(short, long)]
|
|
|
|
ascii_only: bool,
|
|
|
|
|
|
|
|
/// Show CPU architecture
|
|
|
|
#[arg(short = 'x', long)]
|
|
|
|
arch: bool,
|
2024-03-24 13:04:37 +00:00
|
|
|
|
2024-03-24 14:08:46 +00:00
|
|
|
/// Hide terminal colours
|
2024-03-24 13:04:37 +00:00
|
|
|
#[arg(short = 'z', long, default_value_t = false)]
|
|
|
|
hide_colours: bool,
|
2024-03-24 12:48:11 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 13:04:37 +00:00
|
|
|
fn cpu_arch(args: &Args) {
|
2024-03-24 12:48:11 +00:00
|
|
|
if args.arch {
|
|
|
|
let arch = arch();
|
|
|
|
println!("{:>17} {}", "Arch".cyan().bold(), arch);
|
|
|
|
}
|
|
|
|
}
|
2024-03-23 21:58:32 +00:00
|
|
|
|
|
|
|
fn main() {
|
2024-03-24 12:48:11 +00:00
|
|
|
let args = Args::parse();
|
|
|
|
|
2024-03-23 21:58:32 +00:00
|
|
|
let bottom = format!("c({})({})", "\"".red(), "\"".red()).to_string();
|
2024-03-23 23:30:23 +00:00
|
|
|
let ascii = ["(\\ /)", "( . .)", &bottom];
|
2024-03-23 21:58:32 +00:00
|
|
|
|
2024-03-23 23:17:07 +00:00
|
|
|
let hostname = fallible::hostname().unwrap_or(String::from("N/A"));
|
|
|
|
let user = env!("USER");
|
|
|
|
|
2024-03-24 12:48:11 +00:00
|
|
|
let combined = format!("{}@{}", user.italic(), hostname.italic());
|
2024-03-23 23:17:07 +00:00
|
|
|
|
2024-03-23 22:35:06 +00:00
|
|
|
let kernel = System::kernel_version().unwrap_or(String::from("N/A"));
|
|
|
|
let pretty = distro();
|
2024-03-24 14:08:46 +00:00
|
|
|
let wm: &str;
|
2024-03-23 22:35:06 +00:00
|
|
|
|
|
|
|
if cfg!(windows) {
|
|
|
|
wm = "Aero";
|
|
|
|
} else if cfg!(unix) {
|
2024-03-24 14:08:46 +00:00
|
|
|
wm = var("XDG_CURRENT_DESKTOP");
|
|
|
|
} else {
|
|
|
|
wm = "N/A";
|
2024-03-23 21:58:32 +00:00
|
|
|
}
|
2024-03-23 22:35:06 +00:00
|
|
|
|
2024-03-24 12:48:11 +00:00
|
|
|
println!();
|
|
|
|
if !args.ascii_only {
|
|
|
|
println!("{:>48}", combined);
|
2024-03-24 13:04:37 +00:00
|
|
|
cpu_arch(&args);
|
2024-03-24 12:48:11 +00:00
|
|
|
println!("{:>8} {:>6} {}", ascii[0], "OS".blue().bold(), pretty);
|
|
|
|
println!("{:>9} {:>9} {}", ascii[1], "Kernel".red().bold(), kernel);
|
|
|
|
println!("{:>28} {:>4} {}", ascii[2], "WM".green().bold(), wm);
|
|
|
|
} else {
|
|
|
|
for i in ascii {
|
|
|
|
println!(" {}", i);
|
|
|
|
}
|
|
|
|
}
|
2024-03-24 13:04:37 +00:00
|
|
|
|
2024-03-24 13:50:31 +00:00
|
|
|
if !args.hide_colours && !args.ascii_only {
|
2024-03-24 13:04:37 +00:00
|
|
|
println!();
|
2024-03-24 14:08:46 +00:00
|
|
|
let colors = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"];
|
2024-03-24 13:04:37 +00:00
|
|
|
let mut color_string: String = " ".to_owned();
|
|
|
|
for color in colors {
|
|
|
|
color_string.push_str(&format!("{:>3}", "●".color(color)));
|
|
|
|
}
|
|
|
|
println!("{}", color_string);
|
|
|
|
}
|
2024-03-23 21:58:32 +00:00
|
|
|
}
|