Skip to main content

clap_themes/
lib.rs

1//! `clap_themes` is a quick and easy way to add color and style to your
2//! clap-powered CLI!
3//!
4//! ## Examples
5//!
6//! ```
7//! use clap::Parser;
8//!
9//! #[derive(Parser)]
10//! #[clap(styles = clap_themes::CARGO)]
11//! struct Cli {
12//!     /// Here's some good help text!
13//!     #[clap(short, long)]
14//!     arg1: String,
15//! }
16//! ```
17
18use clap::builder::{
19    styling::{Ansi256Color, AnsiColor},
20    Styles,
21};
22
23pub use doom_one::DOOM_ONE;
24
25/// Colored output in the style of clap v3, before they removed color.
26pub const CLAP_V3: Styles = Styles::styled()
27    .header(AnsiColor::Yellow.on_default())
28    .usage(AnsiColor::Yellow.on_default())
29    .placeholder(Ansi256Color(117).on_default())
30    .literal(AnsiColor::Green.on_default());
31
32/// Colored output in the style of the cargo command.
33pub const CARGO: Styles = Styles::styled()
34    .header(AnsiColor::BrightGreen.on_default().bold())
35    .usage(AnsiColor::Yellow.on_default())
36    .placeholder(AnsiColor::Cyan.on_default())
37    .literal(AnsiColor::BrightCyan.on_default().bold());
38
39mod doom_one {
40    use clap::builder::{styling::RgbColor, Styles};
41
42    const RED: RgbColor = RgbColor(0xff, 0x6c, 0x6b);
43    const _DARK_BLUE: RgbColor = RgbColor(0x22, 0x57, 0xA0);
44    const _VIOLET: RgbColor = RgbColor(0xa9, 0xa1, 0xe1);
45    const _ORANGE: RgbColor = RgbColor(0xda, 0x85, 0x48);
46    const YELLOW: RgbColor = RgbColor(0xec, 0xbe, 0x7b);
47    const GREEN: RgbColor = RgbColor(0x98, 0xbe, 0x65);
48    const MAGENTA: RgbColor = RgbColor(0xc6, 0x78, 0xdd);
49
50    /// Colored output in the style of the "doom one" ViM theme.
51    pub const DOOM_ONE: Styles = Styles::styled()
52        .header(YELLOW.on_default().underline())
53        .usage(YELLOW.on_default())
54        .placeholder(GREEN.on_default())
55        .error(RED.on_default())
56        .literal(MAGENTA.on_default());
57}