Add colors to the CLI help menu (#6280)

## Summary

Adds colors to the CLI output.

## Test Plan


<img width="526" alt="Screenshot 2024-08-21 at 00 06 40"
src="https://github.com/user-attachments/assets/88388272-659e-49d4-a641-83f64de55cf0">
<img width="879" alt="Screenshot 2024-08-21 at 00 06 57"
src="https://github.com/user-attachments/assets/26522bd3-c9cf-4359-a8d3-e5c9c72a54aa">
This commit is contained in:
Ahmed Ilyas 2024-08-28 18:43:52 +02:00 committed by GitHub
parent cef3d35405
commit 9f0346592f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 1 deletions

View File

@ -4,7 +4,8 @@ use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use anyhow::{anyhow, Result}; 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 clap::{Args, Parser, Subcommand};
use distribution_types::{FlatIndexLocation, IndexUrl}; use distribution_types::{FlatIndexLocation, IndexUrl};
use pep508_rs::Requirement; use pep508_rs::Requirement;
@ -51,6 +52,13 @@ fn extra_name_with_clap_error(arg: &str) -> Result<ExtraName> {
}) })
} }
// 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)] #[derive(Parser)]
#[command(name = "uv", author, long_version = crate::version::version())] #[command(name = "uv", author, long_version = crate::version::version())]
#[command(about = "An extremely fast Python package manager.")] #[command(about = "An extremely fast Python package manager.")]
@ -62,6 +70,7 @@ fn extra_name_with_clap_error(arg: &str) -> Result<ExtraName> {
disable_help_subcommand = true, disable_help_subcommand = true,
disable_version_flag = true disable_version_flag = true
)] )]
#[command(styles=STYLES)]
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
pub struct Cli { pub struct Cli {
#[command(subcommand)] #[command(subcommand)]