Add colors to --help

This commit is contained in:
Filip Czaplicki 2025-11-23 10:24:17 +01:00 committed by Alejandro González
parent 33cea5603e
commit d7f208abc1

View file

@ -1,10 +1,18 @@
use std::{num::NonZeroU64, path::PathBuf}; use std::{num::NonZeroU64, path::PathBuf};
use clap::builder::Styles;
use clap::builder::styling::{AnsiColor, Effects};
use clap::{Arg, ArgAction, Command, builder::ArgPredicate, value_parser}; use clap::{Arg, ArgAction, Command, builder::ArgPredicate, value_parser};
use parse_size::parse_size; use parse_size::parse_size;
include!("display_chunks.rs"); include!("display_chunks.rs");
const STYLES: Styles = Styles::styled()
.header(AnsiColor::Green.on_default().effects(Effects::BOLD))
.usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
.literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
.placeholder(AnsiColor::Cyan.on_default());
pub fn build_command() -> Command { pub fn build_command() -> Command {
// Note: clap 'wrap_help' is enabled to automatically wrap lines according to terminal width. // Note: clap 'wrap_help' is enabled to automatically wrap lines according to terminal width.
// To keep things tidy though, short help descriptions should be no more than 54 characters, // To keep things tidy though, short help descriptions should be no more than 54 characters,
@ -15,6 +23,7 @@ pub fn build_command() -> Command {
.version(env!("CARGO_PKG_VERSION")) .version(env!("CARGO_PKG_VERSION"))
.author("Joshua Holmer <jholmer.in@gmail.com>") .author("Joshua Holmer <jholmer.in@gmail.com>")
.about("Losslessly improve compression of PNG files") .about("Losslessly improve compression of PNG files")
.styles(STYLES)
.arg( .arg(
Arg::new("files") Arg::new("files")
.help("File(s) to compress (use '-' for stdin)") .help("File(s) to compress (use '-' for stdin)")