Skip to content

Commit

Permalink
Make HelpProvider colors configurable (#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankRay78 committed Jan 18, 2024
1 parent d5b4621 commit 9cc888e
Show file tree
Hide file tree
Showing 21 changed files with 630 additions and 118 deletions.
28 changes: 28 additions & 0 deletions docs/input/cli/command-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ The help is also context aware and tailored depending on what has been specified

`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`.

## Styling the help text

Basic styling is applied to the generated help text by default, however this is configurable.

`HelpProviderStyle` is the `Spectre.Console` class that holds the style information for the help text.

The default theme shipped with Spectre.Console is provided by a factory method, `HelpProviderStyle.Default`.

However, you can explicitly set a custom theme when configuring a CommandApp, for example:

```csharp
config.Settings.HelpProviderStyles = new HelpProviderStyle()
{
Description = new DescriptionStyle()
{
Header = "bold",
},
};
```

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:

```csharp
config.Settings.HelpProviderStyles = null;
```

See [Markup](../markup) for information about the use of markup in Spectre.Console, and [Styles](xref:styles) for a listing of supported styles.

## Custom help providers

Whilst it shouldn't be common place to implement your own help provider, it is however possible.
Expand Down
4 changes: 4 additions & 0 deletions examples/Cli/Help/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Spectre.Console.Cli;
using Spectre.Console.Cli.Help;

namespace Help;

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

return app.Run(args);
Expand Down
Loading

0 comments on commit 9cc888e

Please sign in to comment.