Skip to content

Commit 593ca77

Browse files
committed
feat(cli): Add colors to CLI help outputs
1 parent 7002613 commit 593ca77

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ version = "0.8"
8484
[dependencies.clap]
8585
version = "4.4"
8686
optional = true
87-
features = ["derive", "string", "wrap_help"]
87+
features = ["color", "derive", "string", "wrap_help"]
8888

8989
[dependencies.mlua]
9090
workspace = true

src/bin/sile.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use sile::cli::Cli;
1+
use sile::cli::{Cli, STYLES};
22

33
use snafu::prelude::*;
44

@@ -34,7 +34,10 @@ fn main() -> Result<()> {
3434
.strip_prefix("SILE ")
3535
.unwrap_or("")
3636
.to_string();
37-
let app = Cli::command().version(version).long_version(long_version);
37+
let app = Cli::command()
38+
.version(version)
39+
.long_version(long_version)
40+
.styles(STYLES);
3841
let matches = app.get_matches();
3942
let args = Cli::from_arg_matches(&matches).context(ArgsSnafu)?;
4043
sile::run(

src/cli.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use clap::builder::styling::{AnsiColor, Styles};
12
use clap::Parser;
23
use std::path::PathBuf;
34

@@ -146,3 +147,12 @@ pub struct Cli {
146147
#[clap(short, long)]
147148
pub traceback: bool,
148149
}
150+
151+
pub const STYLES: Styles = Styles::styled()
152+
.header(AnsiColor::Magenta.on_default().bold())
153+
.usage(AnsiColor::Yellow.on_default().bold())
154+
.literal(AnsiColor::BrightCyan.on_default().bold())
155+
.placeholder(AnsiColor::Cyan.on_default())
156+
.error(AnsiColor::BrightRed.on_default().bold())
157+
.valid(AnsiColor::BrightGreen.on_default().bold())
158+
.invalid(AnsiColor::BrightYellow.on_default().bold());

0 commit comments

Comments
 (0)