Skip to content

Commit 9cc888e

Browse files
authored
Make HelpProvider colors configurable (#1408)
1 parent d5b4621 commit 9cc888e

21 files changed

Lines changed: 630 additions & 118 deletions

docs/input/cli/command-help.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ The help is also context aware and tailored depending on what has been specified
1515

1616
`HelpProvider` is the `Spectre.Console` class responsible for determining context and preparing the help text to write to the console. It is an implementation of the public interface `IHelpProvider`.
1717

18+
## Styling the help text
19+
20+
Basic styling is applied to the generated help text by default, however this is configurable.
21+
22+
`HelpProviderStyle` is the `Spectre.Console` class that holds the style information for the help text.
23+
24+
The default theme shipped with Spectre.Console is provided by a factory method, `HelpProviderStyle.Default`.
25+
26+
However, you can explicitly set a custom theme when configuring a CommandApp, for example:
27+
28+
```csharp
29+
config.Settings.HelpProviderStyles = new HelpProviderStyle()
30+
{
31+
Description = new DescriptionStyle()
32+
{
33+
Header = "bold",
34+
},
35+
};
36+
```
37+
38+
Removing all styling from help text is also possible, a good choice for ensuring maximum accessibility. This is configured by clearing the style provider entirely:
39+
40+
```csharp
41+
config.Settings.HelpProviderStyles = null;
42+
```
43+
44+
See [Markup](../markup) for information about the use of markup in Spectre.Console, and [Styles](xref:styles) for a listing of supported styles.
45+
1846
## Custom help providers
1947

2048
Whilst it shouldn't be common place to implement your own help provider, it is however possible.

examples/Cli/Help/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Spectre.Console.Cli;
2+
using Spectre.Console.Cli.Help;
23

34
namespace Help;
45

@@ -12,6 +13,9 @@ public static int Main(string[] args)
1213
{
1314
// Register the custom help provider
1415
config.SetHelpProvider(new CustomHelpProvider(config.Settings));
16+
17+
// Render an unstyled help text for maximum accessibility
18+
config.Settings.HelpProviderStyles = null;
1519
});
1620

1721
return app.Run(args);

0 commit comments

Comments
 (0)