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

Add support for configuring colors and styles #3406

Closed
wants to merge 6 commits into from

Conversation

codeinred
Copy link

This pull request adds support for configuring colors and styles in Clap. It does this by adding a StyleSpec class that holds information about the termcolor::ColorSpecs associated with various styles. This is added as a component of the App class, and it allows users to set colors, styles, and other such aspects of Clap.

For example, I can now write the following:

use clap::{Color, IntoApp, Parser, Style};

fn main() {
    let app = Args::into_app()
        .bold(Style::Good, true)
        .bold(Style::Warning, true)
        .foreground(Style::Warning, Some(Color::Green));

    // ...

In this example, this will set text displayed in Style::Good and Style::Warning to bold, and also update the warning style color to Green.

Before Customization:
image

After Customization:
image

A note on styles

This pull request functions within the bounds of the Style enum already defined by Clap, inside src/output/fmt.rs. We may want to give the options defined in this enum more descriptive names (for example, Style::Warning would become Style::SectionHeader, which is what it's used for when printing --help). We may also want to increase the number of styles (so that there's a Warning style and a SectionHeader style)

Considerations on the API

This adds Style as part of claps public API, and it also exposes termcolor::Colorasclap::Color`.

@codeinred
Copy link
Author

I made some changes to resolve linter errors and to squash the commits. This issue has been closed. Please see #3407 instead.

@codeinred codeinred closed this Feb 5, 2022
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.

1 participant