fn paint(text: &str, code: &str, color: bool) -> String {
if color {
format!("\x1b[{code}m{text}\x1b[0m")
} else {
text.to_string()
}
}
pub fn print() {
let color = mandible_tui::style::color_enabled_from_env();
let dim = "2";
let bold = "1";
println!();
println!(
" {} {}",
paint(env!("CARGO_PKG_NAME"), bold, color),
paint(&format!("v{}", env!("CARGO_PKG_VERSION")), dim, color),
);
println!(
" {}",
paint(
"A TUI manual for every command-line tool you have.",
dim,
color
)
);
println!();
println!(" {}", paint("The rule:", bold, color));
println!(" No per-tool logic, ever. Help text isn't written by hand, it's");
println!(" generated โ so mandible learns the generators (clap, cobra, argparse,");
println!(" click, GNU argp, and the rest), not the tools. Fixing the argparse");
println!(" grammar improves every Python CLI ever written.");
println!();
println!(" {}", paint("When it can't parse something:", bold, color));
println!(" It shows you the author's own text, untouched, and says so.");
println!(" It never invents structure it didn't find.");
println!();
println!(
" {} {}",
paint("repository", dim, color),
env!("CARGO_PKG_REPOSITORY")
);
println!(
" {} {}",
paint("license", dim, color),
env!("CARGO_PKG_LICENSE")
);
println!();
println!(
" {}",
paint(
"try: mandible git mandible docker mandible --doctor <tool>",
dim,
color
)
);
println!();
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn paint_is_a_no_op_without_color() {
assert_eq!(paint("hi", "1", false), "hi");
}
#[test]
fn paint_wraps_and_resets_with_color() {
let painted = paint("hi", "1", true);
assert!(painted.starts_with("\x1b[1m"));
assert!(painted.ends_with("\x1b[0m"));
}
}