From 9f0346592faa7d9479d22b2b374b85e3aa721c67 Mon Sep 17 00:00:00 2001 From: Ahmed Ilyas Date: Wed, 28 Aug 2024 18:43:52 +0200 Subject: [PATCH] Add colors to the CLI help menu (#6280) ## Summary Adds colors to the CLI output. ## Test Plan Screenshot 2024-08-21 at 00 06 40 Screenshot 2024-08-21 at 00 06 57 --- crates/uv-cli/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 62cdac90d..1cdefd25e 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -4,7 +4,8 @@ use std::path::PathBuf; use std::str::FromStr; use anyhow::{anyhow, Result}; -use clap::builder::styling::Style; +use clap::builder::styling::{AnsiColor, Effects, Style}; +use clap::builder::Styles; use clap::{Args, Parser, Subcommand}; use distribution_types::{FlatIndexLocation, IndexUrl}; use pep508_rs::Requirement; @@ -51,6 +52,13 @@ fn extra_name_with_clap_error(arg: &str) -> Result { }) } +// Configures Clap v3-style help menu colors +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()); + #[derive(Parser)] #[command(name = "uv", author, long_version = crate::version::version())] #[command(about = "An extremely fast Python package manager.")] @@ -62,6 +70,7 @@ fn extra_name_with_clap_error(arg: &str) -> Result { disable_help_subcommand = true, disable_version_flag = true )] +#[command(styles=STYLES)] #[allow(clippy::struct_excessive_bools)] pub struct Cli { #[command(subcommand)]