pub struct CliFormat;
impl CliFormat {
pub const TITLE_1: &'static str = "\x1b[1;38;5;219m"; pub const TITLE_2: &'static str = "\x1b[1;38;5;213m"; pub const CORE: &'static str = "\x1b[38;5;219m"; pub const ANIMATION: &'static str = "\x1b[38;5;213m"; pub const GENERAL: &'static str = "\x1b[38;5;147m"; pub const PATTERN: &'static str = "\x1b[38;5;117m"; pub const RESET: &'static str = "\x1b[0m";
pub const HEADING_INPUT: &'static str = "📁 Input/Output";
pub const HEADING_CORE: &'static str = "🎨 Core Options";
pub const HEADING_ANIMATION: &'static str = "✨ Animation";
pub const HEADING_GENERAL: &'static str = "⚙️ General";
pub const HEADING_WAVE: &'static str = "🌊 Wave/Ripple";
pub const HEADING_PLASMA: &'static str = "🌀 Plasma/Perlin";
pub const HEADING_SPIRAL: &'static str = "💫 Spiral/Diamond";
pub const HEADING_OTHER: &'static str = "📐 Other";
pub const PARAM: &'static str = "\x1b[38;5;149m"; pub const PARAM_VALUE: &'static str = "\x1b[38;5;215m"; pub const DESCRIPTION: &'static str = "\x1b[38;5;252m"; pub const SEPARATOR: &'static str = "\x1b[38;5;239m";
pub const HEADING_PARAMS: &'static str = "🎯 Pattern Parameters";
pub const HEADING_EXAMPLES: &'static str = "📚 Examples";
pub fn wrap(color: &str, text: &str) -> String {
format!("{}{}{}", color, text, Self::RESET)
}
pub fn core(text: &str) -> String {
Self::wrap(Self::CORE, text)
}
pub fn animation(text: &str) -> String {
Self::wrap(Self::ANIMATION, text)
}
pub fn general(text: &str) -> String {
Self::wrap(Self::GENERAL, text)
}
pub fn pattern(text: &str) -> String {
Self::wrap(Self::PATTERN, text)
}
pub fn param(text: &str) -> String {
Self::wrap(Self::PARAM, text)
}
pub fn param_value(text: &str) -> String {
Self::wrap(Self::PARAM_VALUE, text)
}
pub fn description(text: &str) -> String {
Self::wrap(Self::DESCRIPTION, text)
}
pub fn separator(text: &str) -> String {
Self::wrap(Self::SEPARATOR, text)
}
pub fn highlight_description(text: &str) -> String {
let highlights = [
("select", Self::PARAM),
("enable", Self::PARAM),
("disable", Self::PARAM),
("customize", Self::PARAM),
("load", Self::PARAM),
("specify", Self::PARAM),
("use", Self::PARAM),
("reads", Self::PARAM),
("0.0-1.0", Self::PARAM_VALUE),
("0.1-10.0", Self::PARAM_VALUE),
("0.1-2.0", Self::PARAM_VALUE),
("1-144", Self::PARAM_VALUE),
("true/false", Self::PARAM_VALUE),
("infinite", Self::PARAM_VALUE),
("pattern", Self::CORE),
("theme", Self::CORE),
("gradient", Self::CORE),
("color", Self::CORE),
("animation", Self::ANIMATION),
("animated", Self::ANIMATION),
("transitions", Self::ANIMATION),
("fps", Self::ANIMATION),
("speed", Self::ANIMATION),
("duration", Self::ANIMATION),
("stdin", Self::GENERAL),
("input", Self::GENERAL),
("output", Self::GENERAL),
("file", Self::GENERAL),
("--param", Self::PATTERN),
("parameters", Self::PATTERN),
("key=value", Self::PATTERN),
("comma-separated", Self::PATTERN),
];
let mut result = text.to_string();
for (term, color) in highlights.iter() {
let pattern = format!(r"\b{}\b", regex::escape(term));
if let Ok(re) = regex::Regex::new(&pattern) {
result = re
.replace_all(&result, format!("{}{}{}", color, term, Self::RESET))
.to_string();
}
}
format!("{}{}{}", Self::DESCRIPTION, result, Self::RESET)
}
}
pub trait PadToWidth {
fn pad_to_width(&self, width: usize) -> String;
}
impl PadToWidth for String {
fn pad_to_width(&self, width: usize) -> String {
if self.len() >= width {
self.clone()
} else {
format!("{:<width$}", self, width = width)
}
}
}
impl PadToWidth for &str {
fn pad_to_width(&self, width: usize) -> String {
if self.len() >= width {
self.to_string()
} else {
format!("{:<width$}", self, width = width)
}
}
}