Skip to content

Commit 09e6af1

Browse files
authored
[ruff+ty] Add colour to --help (#21337)
1 parent 76efc80 commit 09e6af1

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

crates/ruff/src/args.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::sync::Arc;
77

88
use crate::commands::completions::config::{OptionString, OptionStringParser};
99
use anyhow::bail;
10+
use clap::builder::Styles;
11+
use clap::builder::styling::{AnsiColor, Effects};
1012
use clap::builder::{TypedValueParser, ValueParserFactory};
1113
use clap::{Parser, Subcommand, command};
1214
use colored::Colorize;
@@ -78,6 +80,13 @@ impl GlobalConfigArgs {
7880
}
7981
}
8082

83+
// Configures Clap v3-style help menu colors
84+
const STYLES: Styles = Styles::styled()
85+
.header(AnsiColor::Green.on_default().effects(Effects::BOLD))
86+
.usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
87+
.literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
88+
.placeholder(AnsiColor::Cyan.on_default());
89+
8190
#[derive(Debug, Parser)]
8291
#[command(
8392
author,
@@ -86,6 +95,7 @@ impl GlobalConfigArgs {
8695
after_help = "For help with a specific command, see: `ruff help <command>`."
8796
)]
8897
#[command(version)]
98+
#[command(styles = STYLES)]
8999
pub struct Args {
90100
#[command(subcommand)]
91101
pub(crate) command: Command,

crates/ty/src/args.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::logging::Verbosity;
22
use crate::python_version::PythonVersion;
3+
use clap::builder::Styles;
4+
use clap::builder::styling::{AnsiColor, Effects};
35
use clap::error::ErrorKind;
46
use clap::{ArgAction, ArgMatches, Error, Parser};
57
use ruff_db::system::SystemPathBuf;
@@ -8,9 +10,17 @@ use ty_project::metadata::options::{EnvironmentOptions, Options, SrcOptions, Ter
810
use ty_project::metadata::value::{RangedValue, RelativeGlobPattern, RelativePathBuf, ValueSource};
911
use ty_python_semantic::lint;
1012

13+
// Configures Clap v3-style help menu colors
14+
const STYLES: Styles = Styles::styled()
15+
.header(AnsiColor::Green.on_default().effects(Effects::BOLD))
16+
.usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
17+
.literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
18+
.placeholder(AnsiColor::Cyan.on_default());
19+
1120
#[derive(Debug, Parser)]
1221
#[command(author, name = "ty", about = "An extremely fast Python type checker.")]
1322
#[command(long_version = crate::version::version())]
23+
#[command(styles = STYLES)]
1424
pub struct Cli {
1525
#[command(subcommand)]
1626
pub(crate) command: Command,

0 commit comments

Comments
 (0)