From e07ccd9f66a5487baee61e907bd6aecc35b7d9c2 Mon Sep 17 00:00:00 2001 From: Will Baldoumas <45316999+wbaldoumas@users.noreply.github.com> Date: Mon, 13 Nov 2023 09:23:09 -0800 Subject: [PATCH] Allow Confirmation Prompt Styling (#1210) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Allow Confirmation Prompt Styling * Remove style null check Co-authored-by: Cédric Luthi * Remove style null coalesce Co-authored-by: Cédric Luthi * Update comment Co-authored-by: Cédric Luthi * Remove style null check Co-authored-by: Cédric Luthi * Update comment Co-authored-by: Cédric Luthi * Remove style null coalesce Co-authored-by: Cédric Luthi --------- Co-authored-by: Cédric Luthi --- .../ConfirmationPromptExtensions.cs | 34 +++++++++++++++++++ .../Prompts/ConfirmationPrompt.cs | 12 +++++++ 2 files changed, 46 insertions(+) diff --git a/src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs b/src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs index 24a3e90b1..5fd4bda62 100644 --- a/src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs +++ b/src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs @@ -42,6 +42,23 @@ public static ConfirmationPrompt HideChoices(this ConfirmationPrompt obj) return ShowChoices(obj, false); } + /// + /// Sets the style in which the list of choices is displayed. + /// + /// The confirmation prompt. + /// The style to use for displaying the choices or to use the default style (blue). + /// The same instance so that multiple calls can be chained. + public static ConfirmationPrompt ChoicesStyle(this ConfirmationPrompt obj, Style? style) + { + if (obj is null) + { + throw new ArgumentNullException(nameof(obj)); + } + + obj.ChoicesStyle = style; + return obj; + } + /// /// Show or hide the default value. /// @@ -79,6 +96,23 @@ public static ConfirmationPrompt HideDefaultValue(this ConfirmationPrompt obj) return ShowDefaultValue(obj, false); } + /// + /// Sets the style in which the default value is displayed. + /// + /// The confirmation prompt. + /// The default value style or to use the default style (green). + /// The same instance so that multiple calls can be chained. + public static ConfirmationPrompt DefaultValueStyle(this ConfirmationPrompt obj, Style? style) + { + if (obj is null) + { + throw new ArgumentNullException(nameof(obj)); + } + + obj.DefaultValueStyle = style; + return obj; + } + /// /// Sets the "invalid choice" message for the prompt. /// diff --git a/src/Spectre.Console/Prompts/ConfirmationPrompt.cs b/src/Spectre.Console/Prompts/ConfirmationPrompt.cs index 4909ee2b2..5257d5233 100644 --- a/src/Spectre.Console/Prompts/ConfirmationPrompt.cs +++ b/src/Spectre.Console/Prompts/ConfirmationPrompt.cs @@ -39,6 +39,16 @@ public sealed class ConfirmationPrompt : IPrompt /// public bool ShowDefaultValue { get; set; } = true; + /// + /// Gets or sets the style in which the default value is displayed. Defaults to green when . + /// + public Style? DefaultValueStyle { get; set; } + + /// + /// Gets or sets the style in which the list of choices is displayed. Defaults to blue when . + /// + public Style? ChoicesStyle { get; set; } + /// /// Gets or sets the string comparer to use when comparing user input /// against Yes/No choices. @@ -72,8 +82,10 @@ public async Task ShowAsync(IAnsiConsole console, CancellationToken cancel .InvalidChoiceMessage(InvalidChoiceMessage) .ValidationErrorMessage(InvalidChoiceMessage) .ShowChoices(ShowChoices) + .ChoicesStyle(ChoicesStyle) .ShowDefaultValue(ShowDefaultValue) .DefaultValue(DefaultValue ? Yes : No) + .DefaultValueStyle(DefaultValueStyle) .AddChoice(Yes) .AddChoice(No);