Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(styles): make styles example use a const #5636

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

gibfahn
Copy link
Contributor

@gibfahn gibfahn commented Aug 8, 2024

I was trying to set up colours for the derive macro, and copying this didn't immediately work, but using .bold() as per #3234 (comment) did work, so figured it would be worth updating the defaults so things are a bit easier for the next person.


Commits (oldest to newest)

6f215ee refactor(styles): make styles example use a const

This makes it easier to copy this example for use in the derive API,
like so:

const STYLES: Styles = Styles::styled()
    .header(AnsiColor::Green.on_default().bold())
    .usage(AnsiColor::Green.on_default().bold())
    .literal(AnsiColor::Blue.on_default().bold())
    .placeholder(AnsiColor::Cyan.on_default());

#[derive(Parser)]
#[clap(styles = STYLES)]
struct Cmd {
  ...
}

If you use the | method then it's not a constant function.


@epage
Copy link
Member

epage commented Aug 8, 2024

Looks like this needs to bump the version of anstyle to pass CI

This makes it easier to copy this example for use in the derive API,
like so:

```rust
const STYLES: Styles = Styles::styled()
    .header(AnsiColor::Green.on_default().bold())
    .usage(AnsiColor::Green.on_default().bold())
    .literal(AnsiColor::Blue.on_default().bold())
    .placeholder(AnsiColor::Cyan.on_default());

#[derive(Parser)]
#[clap(styles = STYLES)]
struct Cmd {
  ...
}
```

If you use the `|` method then it's not a constant function.
@epage epage merged commit 6fb49d0 into clap-rs:master Aug 8, 2024
24 of 25 checks passed
@epage
Copy link
Member

epage commented Aug 8, 2024

Thanks!

@gibfahn gibfahn deleted the styles_const branch August 8, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants