Skip to content

Commit

Permalink
teeny tiny update, added -v command and acsii tests, version 0.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
charklie committed May 9, 2024
1 parent caa2521 commit 4d3a7b8
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rsftch"
version = "0.5.3"
version = "0.5.4"
edition = "2021"
authors = ["Charklie charliejohanid@gmail.com"]
license = "MIT"
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
96 changes: 60 additions & 36 deletions src/ascii.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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>) -> 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\\____/ .__/\\__/_//_/___/\\_,_/___/\\__/ \n /_/ "),
os_ascii!(overriden_ascii, "rasp", " ___ __ _ \n / _ \\___ ____ ___ / / (_)__ ____ \n / , _/ _ `(_-</ _ \\/ _ \\/ / _ `/ _ \\\n/_/|_|\\_,_/___/ .__/_.__/_/\\_,_/_//_/\n /_/ "),
os_ascii!(overriden_ascii, "mint", " __ ____ __ \n / |/ (_)__ / /_\n / /|_/ / / _ \\/ __/\n/_/ /_/_/_//_/\\__/"),
os_ascii!(overriden_ascii, "mx", " __ ____ __ __ _ \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\\____/ .__/\\__/_//_/___/\\_,_/___/\\__/ \n /_/"),
ascii!(overriden_ascii, "rasp", " ___ __ _ \n / _ \\___ ____ ___ / / (_)__ ____ \n / , _/ _ `(_-</ _ \\/ _ \\/ / _ `/ _ \\\n/_/|_|\\_,_/___/ .__/_.__/_/\\_,_/_//_/\n /_/"),
ascii!(overriden_ascii, "mint", " __ ____ __ \n / |/ (_)__ / /_\n / /|_/ / / _ \\/ __/\n/_/ /_/_/_//_/\\__/"),
ascii!(overriden_ascii, "mx", " __ ____ __ __ _ \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 {
Expand Down
19 changes: 6 additions & 13 deletions src/fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/info_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn get_default_info_lists(section: &str) -> Vec<String> {
"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())
Expand Down
29 changes: 17 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,52 @@ 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();
}
}
"--info" => {
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();
}
}
"-o" | "--override" => {
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" => {
if count + 1 < args.len() && !args[count + 1].starts_with("--") {
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" => {
if count + 1 < args.len() && !args[count + 1].starts_with("--") {
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;
}
_ => {}
};
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -259,7 +264,7 @@ fn info(
let res = InfoItem {
title: "res",
alignment_space: 5,
icon: "",
icon: "",
value: get_res(),
};

Expand Down

0 comments on commit 4d3a7b8

Please sign in to comment.