mirror of
https://github.com/Atsukoro1/ponyfetch.git
synced 2024-11-23 12:47:59 +01:00
feat: 🎸 Command line arguments
This commit is contained in:
parent
da7121e889
commit
c16a99c456
5 changed files with 71 additions and 31 deletions
|
@ -1,4 +1,7 @@
|
|||
[package]
|
||||
name = "ponyfetch"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.0.29", features = ["derive"] }
|
15
src/args.rs
Normal file
15
src/args.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
#[derive(clap::Parser)]
|
||||
#[clap(
|
||||
version = "1.0",
|
||||
author = "Atsukoro1",
|
||||
about = "Just a simple cross-platform neofetch for all the bronies out there."
|
||||
)]
|
||||
pub struct Args {
|
||||
#[clap(short, long, required = false, default_value = "rainbowdash")]
|
||||
/// Defines what ASCII pony to print.
|
||||
pub pony: String,
|
||||
|
||||
#[clap(short, long, required = false, default_value = "0")]
|
||||
/// Defines what color to print the output it
|
||||
pub color: String
|
||||
}
|
|
@ -1,23 +1,36 @@
|
|||
pub fn print_cyan(text: &str, inline: bool) {
|
||||
if inline {
|
||||
print!("\x1b[36m{}\x1b[0m", text);
|
||||
} else {
|
||||
println!("\x1b[36m{}\x1b[0m", text);
|
||||
}
|
||||
}
|
||||
// make const with color names and match them with unicode symbol for color
|
||||
const COLORS : [(&str, &str); 17] = [
|
||||
("black", "\u{001b}[30m"),
|
||||
("red", "\u{001b}[31m"),
|
||||
("green", "\u{001b}[32m"),
|
||||
("yellow", "\u{001b}[33m"),
|
||||
("blue", "\u{001b}[34m"),
|
||||
("magenta", "\u{001b}[35m"),
|
||||
("cyan", "\u{001b}[36m"),
|
||||
("white", "\u{001b}[37m"),
|
||||
("bright_black", "\u{001b}[90m"),
|
||||
("bright_red", "\u{001b}[91m"),
|
||||
("bright_green", "\u{001b}[92m"),
|
||||
("bright_yellow", "\u{001b}[93m"),
|
||||
("bright_blue", "\u{001b}[94m"),
|
||||
("bright_magenta", "\u{001b}[95m"),
|
||||
("bright_cyan", "\u{001b}[96m"),
|
||||
("bright_white", "\u{001b}[97m"),
|
||||
("cyan_bold", "\u{001b}[36m\u{001b}[1m"),
|
||||
];
|
||||
|
||||
pub fn print_cyan_bold(text: &str, inline: bool) {
|
||||
if inline {
|
||||
print!("\x1b[36m\x1b[1m{}\x1b[0m", text);
|
||||
} else {
|
||||
println!("\x1b[36m\x1b[1m{}\x1b[0m", text);
|
||||
pub fn print(text: &str, inline: bool, color: &str) {
|
||||
let mut color = color;
|
||||
if color == "rainbowdash" {
|
||||
color = "bright_magenta";
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_bold(text: &str, inline: bool) {
|
||||
let color = color;
|
||||
let color = COLORS.iter().find(|(name, _)| name == &color).unwrap().1;
|
||||
|
||||
if inline {
|
||||
print!("\x1b[1m{}\x1b[0m", text);
|
||||
print!("{}{}", color, text);
|
||||
} else {
|
||||
println!("\x1b[1m{}\x1b[0m", text);
|
||||
println!("{}{}", color, text);
|
||||
}
|
||||
}
|
|
@ -1,39 +1,39 @@
|
|||
use super::{file::file_open, colors::print_cyan_bold};
|
||||
use crate::{helpers::{self, colors::print_bold}, ActionType};
|
||||
use super::{file::file_open, colors::print};
|
||||
use crate::{helpers::{self}, ActionType};
|
||||
|
||||
pub fn print_detail(title: &str, value: String, atype: ActionType) {
|
||||
pub fn print_detail(title: &str, value: String, atype: ActionType, color: &str) {
|
||||
print!(" ");
|
||||
|
||||
match atype {
|
||||
ActionType::Details => {
|
||||
helpers::colors::print_cyan_bold(&title, true);
|
||||
helpers::colors::print(&title, true, color);
|
||||
for _ in 0..(10 - title.len()) {
|
||||
print!(" ");
|
||||
}
|
||||
|
||||
helpers::colors::print_bold(" : ", true);
|
||||
helpers::colors::print(" : ", true, "white");
|
||||
|
||||
print!("{}", &value);
|
||||
},
|
||||
ActionType::Delimiter => {
|
||||
print_bold("-----------------------------", true);
|
||||
print("-----------------------------", true, "white");
|
||||
},
|
||||
ActionType::HostInfo => {
|
||||
print_bold(&format!(
|
||||
print(&format!(
|
||||
"{}@{}",
|
||||
title,
|
||||
value
|
||||
), true);
|
||||
), true, color);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn print_ponyline(line: u16, pony: &str) {
|
||||
pub fn print_ponyline(line: u16, pony: &str, color: &str) {
|
||||
file_open(&format!("ponies/{}.txt", pony).to_string())
|
||||
.lines()
|
||||
.skip(line as usize)
|
||||
.take(1)
|
||||
.for_each(|line| {
|
||||
print_cyan_bold(line, true);
|
||||
print(line, true, color);
|
||||
});
|
||||
}
|
17
src/main.rs
17
src/main.rs
|
@ -1,5 +1,9 @@
|
|||
use clap::Parser;
|
||||
use args::Args;
|
||||
|
||||
mod helpers;
|
||||
mod system;
|
||||
mod args;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum ActionType {
|
||||
|
@ -68,8 +72,10 @@ const ACTIONS: [Action; 10] = [
|
|||
];
|
||||
|
||||
fn main() {
|
||||
let args: Args = Args::parse();
|
||||
|
||||
for i in 0..12 {
|
||||
helpers::print::print_ponyline(i, "rainbowdash");
|
||||
helpers::print::print_ponyline(i, &args.pony, &args.color);
|
||||
|
||||
if ACTIONS.get(i as usize).is_none() {
|
||||
println!();
|
||||
|
@ -81,7 +87,8 @@ fn main() {
|
|||
helpers::print::print_detail(
|
||||
&system::host::get_user(),
|
||||
system::host::get_hostname(),
|
||||
ActionType::HostInfo
|
||||
ActionType::HostInfo,
|
||||
&args.color
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -89,7 +96,8 @@ fn main() {
|
|||
helpers::print::print_detail(
|
||||
"",
|
||||
"".to_string(),
|
||||
ActionType::Delimiter
|
||||
ActionType::Delimiter,
|
||||
args.color.as_str()
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -97,7 +105,8 @@ fn main() {
|
|||
helpers::print::print_detail(
|
||||
ACTIONS[i as usize].name.unwrap(),
|
||||
ACTIONS[i as usize].func.unwrap()(),
|
||||
ACTIONS[i as usize].action_type
|
||||
ACTIONS[i as usize].action_type,
|
||||
args.color.as_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue