From 3f4d538f5a3450e0f368fdf246fde1aa2803a27e Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Sun, 24 Mar 2024 12:48:11 +0000 Subject: [PATCH] feat: some arguments and an option to only show ASCII art --- Cargo.lock | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/main.rs | 44 +++++++++++++++---- 3 files changed, 160 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5be98d3..0f6c302 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,54 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -18,6 +66,7 @@ checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa" name = "bunbun" version = "1.0.0" dependencies = [ + "clap", "colored", "sysinfo", "whoami", @@ -29,6 +78,52 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "colored" version = "2.1.0" @@ -36,7 +131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -76,6 +171,12 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "js-sys" version = "0.3.69" @@ -165,6 +266,12 @@ dependencies = [ "bitflags", ] +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + [[package]] name = "syn" version = "2.0.53" @@ -197,6 +304,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "wasite" version = "0.1.0" @@ -328,6 +441,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index de05478..268c216 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "1.0.0" edition = "2021" [dependencies] +clap = { version = "4.5.3", features = ["derive"] } colored = "2.1.0" sysinfo = "0.30.7" whoami = "1.5.1" diff --git a/src/main.rs b/src/main.rs index 781a79a..052cb2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,17 +2,38 @@ use colored::Colorize; use std::env; use sysinfo::System; use whoami::*; +use clap::Parser; + +/// 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, +} + +fn cpu_arch(args: Args) { + if args.arch { + let arch = arch(); + println!("{:>17} {}", "Arch".cyan().bold(), arch); + } +} fn main() { + let args = Args::parse(); + let bottom = format!("c({})({})", "\"".red(), "\"".red()).to_string(); let ascii = ["(\\ /)", "( . .)", &bottom]; let hostname = fallible::hostname().unwrap_or(String::from("N/A")); let user = env!("USER"); - let arch = arch(); - - let combined = format!("{}@{}", user, hostname); + let combined = format!("{}@{}", user.italic(), hostname.italic()); let kernel = System::kernel_version().unwrap_or(String::from("N/A")); let pretty = distro(); @@ -26,9 +47,16 @@ fn main() { wm = "N/A"; } - println!("{:>32}", combined.italic()); - println!("{:>17} {}", "Arch".cyan().bold(), arch); - 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); + println!(); + if !args.ascii_only { + println!("{:>48}", combined); + cpu_arch(args); + 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); + } + } }