Add support for configuring colors and styles #3406
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds support for configuring colors and styles in Clap. It does this by adding a
StyleSpec
class that holds information about thetermcolor::ColorSpec
s 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:
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:
After Customization:
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 becomeStyle::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 aWarning
style and aSectionHeader
style)Considerations on the API
This adds Style as part of clap
s public API, and it also exposes
termcolor::Coloras
clap::Color`.