From 4219bbbf616dbce6f73d55b94e1686318863caaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Thu, 9 Nov 2023 21:09:44 +0100 Subject: [PATCH] Allow passing a nullable style in DefaultValueStyle() and ChoicesStyle() This will allow to slightly simplify the implementation of #1210 See also related discussion on https://github.com/spectreconsole/spectre.console/pull/1349#discussion_r1388385384 --- src/Spectre.Console/Prompts/TextPrompt.cs | 4 ++-- .../Prompts/TextPromptExtensions.cs | 18 ++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Spectre.Console/Prompts/TextPrompt.cs b/src/Spectre.Console/Prompts/TextPrompt.cs index e48ed60ef..9574df175 100644 --- a/src/Spectre.Console/Prompts/TextPrompt.cs +++ b/src/Spectre.Console/Prompts/TextPrompt.cs @@ -75,12 +75,12 @@ public sealed class TextPrompt : IPrompt, IHasCulture public Func? Validator { get; set; } /// - /// Gets or sets the style in which the default value is displayed. + /// 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. + /// Gets or sets the style in which the list of choices is displayed. Defaults to blue when . /// public Style? ChoicesStyle { get; set; } diff --git a/src/Spectre.Console/Prompts/TextPromptExtensions.cs b/src/Spectre.Console/Prompts/TextPromptExtensions.cs index ea023dd8d..4fad7843a 100644 --- a/src/Spectre.Console/Prompts/TextPromptExtensions.cs +++ b/src/Spectre.Console/Prompts/TextPromptExtensions.cs @@ -330,20 +330,15 @@ public static TextPrompt WithConverter(this TextPrompt obj, Func /// The prompt result type. /// The prompt. - /// The default value style. + /// The default value style or to use the default style (green). /// The same instance so that multiple calls can be chained. - public static TextPrompt DefaultValueStyle(this TextPrompt obj, Style style) + public static TextPrompt DefaultValueStyle(this TextPrompt obj, Style? style) { if (obj is null) { throw new ArgumentNullException(nameof(obj)); } - if (style is null) - { - throw new ArgumentNullException(nameof(style)); - } - obj.DefaultValueStyle = style; return obj; } @@ -353,20 +348,15 @@ public static TextPrompt DefaultValueStyle(this TextPrompt obj, Style s /// /// The prompt result type. /// The prompt. - /// The style to use for displaying the choices. + /// 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 TextPrompt ChoicesStyle(this TextPrompt obj, Style style) + public static TextPrompt ChoicesStyle(this TextPrompt obj, Style? style) { if (obj is null) { throw new ArgumentNullException(nameof(obj)); } - if (style is null) - { - throw new ArgumentNullException(nameof(style)); - } - obj.ChoicesStyle = style; return obj; }