feat(AppSettings): Enable user-defined colors for help message #3407
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.
Introduction
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:
Motivation
I wanted to be able to make help flags and section headers display in bold for greater readability. Adding support for the ability to customize that involved a rework of a lot of Colorizer code, and it wasn't much additional work to enable other customizations as well.
Changes to clap's API
This section documents changes to the public API of clap
Newly exposed types:
Additions to App
The following functions were added to App, to enable users to customize colors and styles:
A note on the Style enum
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)Internal additions / changes
StyleSpec
, which holds aColorSpec
for eachStyle
StyleSpec
a parameter of Colorizer::newColorizer::new
to include aStyleSpec
Related issues and discussions
Issues:
Discussions: