diff --git a/Cargo.lock b/Cargo.lock index ccb7ea8..f44c058 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -846,7 +846,7 @@ dependencies = [ [[package]] name = "rsftch" -version = "0.5.2" +version = "0.5.4" dependencies = [ "colored", "libmacchina", diff --git a/Cargo.toml b/Cargo.toml index 1aacd10..f05cffb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rsftch" -version = "0.5.3" +version = "0.5.4" edition = "2021" authors = ["Charklie charliejohanid@gmail.com"] license = "MIT" diff --git a/README.md b/README.md index 0491bfe..d79b2b6 100644 --- a/README.md +++ b/README.md @@ -175,13 +175,18 @@ Currently Rsftch only works on GNU/Linux, (most) BSD distributions and (probably ### Note (If) You're wondering why I didn't use clap for command-line argument parsing, I've personally found it slow, and if I do get it to be somewhat fast, its too easy and first rsftch was meant to be a project for me to learn rust so I tried to complicate (some) things and making them in pure rust instead of using a crate to do it for me. -#### Todo +### Contribrutions +All PRs or just an issue recommending an issue is always welcome. Keep in mind that I've only been programming in Rust for circa 2 months, so don't be harsh. + +### Thanks +Thank you to: +- [@siris](https://www.github.com/siris) for helping me with speeding up everything massively and packaging rsftch for Funtoo Linux. +- [@0323pin](https://www.github.com/0323pin) for packaging rsftch on pkgsrc and uploading it to [beucismis/awesome-fetch](https://github.com/beucismis/awesome-fetch). + +### Todo - [X] Configuration via JSON -- [ ] Version command +- [X] Version command +- [ ] Automatic ASCII generation - [ ] Add TOML / JSONC support - [ ] Add support for more info sections (?) -### Thanks -Thank you to: -- @siris for helping me with speeding up everything massively and packaging rsftch for Funtoo Linux. -- @0323pin for publishing rsftch on NetBSD as a package. diff --git a/src/ascii.rs b/src/ascii.rs index ecf84c9..44e4587 100644 --- a/src/ascii.rs +++ b/src/ascii.rs @@ -1,11 +1,19 @@ use crate::fns::{get_os_release_pretty_name, uname_s}; -macro_rules! os_ascii { +macro_rules! ascii { ($overriden_ascii:expr, $search_string:expr, $return_string:expr) => {{ - if get_os_release_pretty_name($overriden_ascii.clone(), "ID") - .unwrap_or("".to_string()) - .to_ascii_lowercase() - .contains(&$search_string.to_ascii_lowercase()) + let os_name = $overriden_ascii + .clone() + .map(|o| o.to_ascii_lowercase()) + .unwrap_or_else(|| { + get_os_release_pretty_name(None, "ID") + .unwrap_or_default() + .to_ascii_lowercase() + }); + let uname = uname_s($overriden_ascii.clone()).to_ascii_lowercase(); + + if os_name.contains(&$search_string.to_ascii_lowercase()) + || uname.contains(&$search_string.to_ascii_lowercase()) { $return_string.to_string() } else { @@ -14,41 +22,57 @@ macro_rules! os_ascii { }}; } -macro_rules! uname_ascii { - ($overriden_ascii:expr, $search_string:expr, $return_string:expr) => {{ - if uname_s($overriden_ascii.clone()) - .to_ascii_lowercase() - .contains(&$search_string.to_ascii_lowercase()) - { - $return_string.to_string() - } else { - "".to_string() - } - }}; +pub fn ascii_test() { + let distros = [ + "Arch Linux", + "Debian", + "Fedora", + "EndeavourOS", + "Void", + "Ubuntu", + "Suse", + "Raspbian", + "Linux Mint", + "MX Linux", + "Gentoo", + "Funtoo", + "Slackware", + "UwUntu", + "NixOS", + "VanillaOS", + "Kali Linux", + "CachyOS", + "NetBSD", + "FreeBSD", + ]; + + for i in distros { + println!("\n{i}: \n{}", get_distro_ascii(Some(i.to_string()))); + } } pub fn get_distro_ascii(overriden_ascii: Option) -> String { let ascii_macros = vec![ - os_ascii!(overriden_ascii, "arch", " ___ __ \n / _ | ____ ____ / / \n / __ | / __// __/ / _ \\\n/_/ |_|/_/ \\__/ /_//_/"), - os_ascii!(overriden_ascii, "debian", " ___ __ _ \n / _ \\___ / / (_)__ ____ \n / // / -_) _ \\/ / _ `/ _ \\\n/____/\\__/_.__/_/\\_,_/_//_/"), - os_ascii!(overriden_ascii, "fedora", " ____ __ \n / __/__ ___/ /__ _______ _\n / _// -_) _ / _ \\/ __/ _ `/\n/_/ \\__/\\_,_/\\___/_/ \\_,_/"), - os_ascii!(overriden_ascii, "endeavour", " ____ __ \n / __/__ ___/ /__ ___ __ _____ __ ______\n / _// _ \\/ _ / -_) _ `/ |/ / _ \\/ // / __/\n/___/_//_/\\_,_/\\__/\\_,_/|___/\\___/\\_,_/_/ "), - os_ascii!(overriden_ascii, "void", " _ __ _ __\n | | / /__ (_)__/ /\n | |/ / _ \\/ / _ / \n |___/\\___/_/\\_,_/"), - os_ascii!(overriden_ascii, "ubuntu", " __ ____ __ \n / / / / / __ _____ / /___ __\n/ /_/ / _ \\/ // / _ \\/ __/ // /\n\\____/_.__/\\_,_/_//_/\\__/\\_,_/"), - os_ascii!(overriden_ascii, "suse", " ____ ____ \n / __ \\___ ___ ___ / __/_ _____ ___ \n/ /_/ / _ \\/ -_) _ \\_\\ \\/ // (_- < / /__/ / _ \\/ // /\\ \\ /\n/_/ /_/_/|_| /____/_/_//_/\\_,_//_\\_\\ "), - os_ascii!(overriden_ascii, "gentoo", " _____ __ \n / ___/__ ___ / /____ ___ \n/ (_ / -_) _ \\/ __/ _ \\/ _ \\\n\\___/\\__/_//_/\\__/\\___/\\___/"), - os_ascii!(overriden_ascii, "funtoo", " ____ __ \n / __/_ _____ / /____ ___ \n / _// // / _ \\/ __/ _ \\/ _ \n/_/ \\_,_/_//_/\\__/\\___/\\___/"), - os_ascii!(overriden_ascii, "slack", " ______ __ \n / __/ /__ _____/ /___ _____ ________ \n _\\ \\/ / _ `/ __/ '_/ |/|/ / _ `/ __/ -_)\n/___/_/\\_,_/\\__/_/\\_\\|__,__/\\_,_/_/ \\__/ "), - os_ascii!(overriden_ascii, "uwuntu", " __ __ __ __ __ \n / / / / __/ / / /__ / /___ __\n/ /_/ / |/|/ / /_/ / _ \\/ __/ // /\n\\____/|__,__/\\____/_//_/\\__/\\_,_/"), - os_ascii!(overriden_ascii, "nix", " _ ___ ____ ____\n / |/ (_)_ __/ __ \\/ __/\n / / /\\ \\ / /_/ /\\ \\ \n/_/|_/_//_\\_\\\\____/___/"), - os_ascii!(overriden_ascii, "vanilla", " _ __ _ ____ \n | | / /__ ____ (_) / /__ _\n | |/ / _ `/ _ \\n/ / / / _ `/\n |___/\\_,_/_//_/_/_/_/\\_,_/"), - os_ascii!(overriden_ascii, "kali", " __ __ ___ \n / //_/__ _/ (_) \n / ,< / _ `/ / / \n/_/|_|\\_,_/_/_/"), - os_ascii!(overriden_ascii, "cachy", " _____ __ \n / ___/__ _____/ / __ __\n/ /__/ _ `/ __/ _ \\/ // /\n\\___/\\_,_/\\__/_//_/\\_, / \n /___/"), - uname_ascii!(overriden_ascii, "netbsd", " _ __ __ ___ _______ \n / |/ /__ / /_/ _ )/ __/ _ \\\n / / -_) __/ _ |\\ \\/ // /\n/_/|_/\\__/\\__/____/___/____/ "), - uname_ascii!(overriden_ascii, "freebsd", " ___ ___ _______ \n / _/______ ___ / _ )/ __/ _ \\\n / _/ __/ -_) -_) _ |\\ \\/ // /\n/_//_/ \\__/\\__/____/___/____/") + ascii!(overriden_ascii, "arch", " ___ __ \n / _ | ____ ____ / / \n / __ | / __// __/ / _ \\\n/_/ |_|/_/ \\__/ /_//_/"), + ascii!(overriden_ascii, "debian", " ___ __ _ \n / _ \\___ / / (_)__ ____ \n / // / -_) _ \\/ / _ `/ _ \\\n/____/\\__/_.__/_/\\_,_/_//_/"), + ascii!(overriden_ascii, "fedora", " ____ __ \n / __/__ ___/ /__ _______ _\n / _// -_) _ / _ \\/ __/ _ `/\n/_/ \\__/\\_,_/\\___/_/ \\_,_/"), + ascii!(overriden_ascii, "endeavour", " ____ __ \n / __/__ ___/ /__ ___ __ _____ __ ______\n / _// _ \\/ _ / -_) _ `/ |/ / _ \\/ // / __/\n/___/_//_/\\_,_/\\__/\\_,_/|___/\\___/\\_,_/_/"), + ascii!(overriden_ascii, "void", " _ __ _ __\n | | / /__ (_)__/ /\n | |/ / _ \\/ / _ / \n |___/\\___/_/\\_,_/"), + ascii!(overriden_ascii, "ubuntu", " __ ____ __ \n / / / / / __ _____ / /___ __\n/ /_/ / _ \\/ // / _ \\/ __/ // /\n\\____/_.__/\\_,_/_//_/\\__/\\_,_/"), + ascii!(overriden_ascii, "suse", " ____ ____ \n / __ \\___ ___ ___ / __/_ _____ ___ \n/ /_/ / _ \\/ -_) _ \\_\\ \\/ // (_- < / /__/ / _ \\/ // /\\ \\ /\n/_/ /_/_/|_| /____/_/_//_/\\_,_//_\\_\\"), + ascii!(overriden_ascii, "gentoo", " _____ __ \n / ___/__ ___ / /____ ___ \n/ (_ / -_) _ \\/ __/ _ \\/ _ \\\n\\___/\\__/_//_/\\__/\\___/\\___/"), + ascii!(overriden_ascii, "funtoo", " ____ __ \n / __/_ _____ / /____ ___ \n / _// // / _ \\/ __/ _ \\/ _ \n/_/ \\_,_/_//_/\\__/\\___/\\___/"), + ascii!(overriden_ascii, "slack", " ______ __ \n / __/ /__ _____/ /___ _____ ________ \n _\\ \\/ / _ `/ __/ '_/ |/|/ / _ `/ __/ -_)\n/___/_/\\_,_/\\__/_/\\_\\|__,__/\\_,_/_/ \\__/ "), + ascii!(overriden_ascii, "uwuntu", " __ __ __ __ __ \n / / / / __/ / / /__ / /___ __\n/ /_/ / |/|/ / /_/ / _ \\/ __/ // /\n\\____/|__,__/\\____/_//_/\\__/\\_,_/"), + ascii!(overriden_ascii, "nix", " _ ___ ____ ____\n / |/ (_)_ __/ __ \\/ __/\n / / /\\ \\ / /_/ /\\ \\ \n/_/|_/_//_\\_\\\\____/___/"), + ascii!(overriden_ascii, "vanilla", " _ __ _ ____ \n | | / /__ ____ (_) / /__ _\n | |/ / _ `/ _ \\/ / / / _ `/\n |___/\\_,_/_//_/_/_/_/\\_,_/"), + ascii!(overriden_ascii, "kali", " __ __ ___ \n / //_/__ _/ (_) \n / ,< / _ `/ / / \n/_/|_|\\_,_/_/_/"), + ascii!(overriden_ascii, "cachy", " _____ __ \n / ___/__ _____/ / __ __\n/ /__/ _ `/ __/ _ \\/ // /\n\\___/\\_,_/\\__/_//_/\\_, / \n /___/"), + ascii!(overriden_ascii, "netbsd", " _ __ __ ___ _______ \n / |/ /__ / /_/ _ )/ __/ _ \\\n / / -_) __/ _ |\\ \\/ // /\n/_/|_/\\__/\\__/____/___/____/ "), + ascii!(overriden_ascii, "freebsd", " ___ ___ _______ \n / _/______ ___ / _ )/ __/ _ \\\n / _/ __/ -_) -_) _ |\\ \\/ // /\n/_//_/ \\__/\\__/____/___/____/") ]; for i in ascii_macros { diff --git a/src/fns.rs b/src/fns.rs index aa3cff6..70ef3fe 100644 --- a/src/fns.rs +++ b/src/fns.rs @@ -10,25 +10,18 @@ use std::{ }; pub fn help() { - println!("Usage: rsftch [OPTION...] [OVERRIDE] [MARGIN] [CONFIG FILE(s)]\n"); + println!("Usage: rsftch [OPTION...] [OVERRIDE] [MARGIN] [CONFIG FILE(s)] [INFO]\n"); println!(" -h, --help, --usage Bring up this menu"); - println!( - " -o, --override Overrides distribution, affects ASCII and \"distro\" info." - ); + println!(" -o, --override Overrides distribution, affects ASCII and \"distro\" info. Running without"); + println!(" an argument prints all possible options"); println!(" -m, --margin Add margin to the info sections, default 1."); println!(" -c, --color-config Specify another color config file, to be used instead of the default one."); println!(" -i, --info-config Specify another info config file, to be used instead of the default one."); - println!( - " --ignore-color-config Ignores the custom color config and uses the default one." - ); - println!( - " --ignore-info-config Ignores the custom info config and uses the default one." - ); + println!(" --ignore-color-config Ignores the custom color config and uses the default one."); + println!(" --ignore-info-config Ignores the custom info config and uses the default one."); println!(" --ignore-config Ignores both configs and uses the default ones."); println!(" --info Only prints the value of the following arguments info, for example"); - println!( - " \"rsftch --info distro\" would output: \"EndeavourOS\"\n" - ); + println!(" \"rsftch --info distro\" would output: \"EndeavourOS\"\n"); println!("Info config is located at: ~/.config/rsftch/info.json"); println!("Color config is located at: ~/.config/rsftch/colors.json"); } diff --git a/src/info_config.rs b/src/info_config.rs index 15ce46e..d3ffde4 100644 --- a/src/info_config.rs +++ b/src/info_config.rs @@ -38,7 +38,7 @@ fn get_default_info_lists(section: &str) -> Vec { "info1" => vec!["os", "host", "shell", "kernel", "packs"], "info2" => vec!["user", "term", "de"], "info3" => vec!["cpu", "gpu", "mem", "uptime", "res"], - _ => vec!["os"], + _ => vec!["empty"], } .iter() .map(|s| s.to_string()) diff --git a/src/main.rs b/src/main.rs index 1a6003f..7096535 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,7 +35,7 @@ fn main() { if count + 1 < args.len() { margin = args[count + 1].parse().unwrap(); } else { - println!("{} Missing argument for margin.\n", "[ERROR]".red()); + println!("[{}] Missing argument for margin.\n", "ERROR".red()); return help(); } } @@ -43,7 +43,7 @@ fn main() { if count + 1 < args.len() && !args[count + 1].starts_with("--") { get_only_info = Some(mem::take(&mut args[count + 1])); } else { - println!("{} Missing argument for info.\n", "[ERROR]".red()); + println!("[{}] Missing argument for info.\n", "ERROR".red()); return help(); } } @@ -51,7 +51,11 @@ fn main() { if count + 1 < args.len() && !args[count + 1].starts_with("--") { overriden_ascii = Some(mem::take(&mut args[count + 1])); } else { - println!("{} Missing argument for override.\n", "[ERROR]".red()); + println!( + "[{}] Missing argument for override, showing all possible.", + "WARNING".yellow() + ); + return ascii_test(); } } "-i" | "--info-config" => { @@ -59,9 +63,10 @@ fn main() { info_custom_config = Some(mem::take(&mut args[count + 1])); } else { println!( - "{} Missing argument for custom info config file.\n", - "[ERROR]".red() + "[{}] Missing argument for custom info config file.\n", + "ERROR".red() ); + return help(); } } "-c" | "--color-config" => { @@ -69,14 +74,13 @@ fn main() { color_custom_config = Some(mem::take(&mut args[count + 1])); } else { println!( - "{} Missing argument for custom color config file.\n", - "[ERROR]".red() + "[{}] Missing argument for custom color config file.\n", + "ERROR".red() ); + return help(); } } - _ => { - continue; - } + _ => {} }; } @@ -190,7 +194,8 @@ fn info( title: "distro", alignment_space: 2, icon: "", - value: get_os_release_pretty_name(overriden_ascii.clone(), "NAME").unwrap_or(uname_s(overriden_ascii.clone())), + value: get_os_release_pretty_name(overriden_ascii.clone(), "NAME") + .unwrap_or(uname_s(overriden_ascii.clone())), }; let hostname = InfoItem { @@ -259,7 +264,7 @@ fn info( let res = InfoItem { title: "res", alignment_space: 5, - icon: "", + icon: "", value: get_res(), };