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

HelpProvider colors should be configurable #1408

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading