mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-14 16:02:50 +08:00
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
This commit is contained in:
parent
29a43686d4
commit
4219bbbf61
@ -75,12 +75,12 @@ public sealed class TextPrompt<T> : IPrompt<T>, IHasCulture
|
||||
public Func<T, ValidationResult>? Validator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see langword="null"/>.
|
||||
/// </summary>
|
||||
public Style? DefaultValueStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see langword="null"/>.
|
||||
/// </summary>
|
||||
public Style? ChoicesStyle { get; set; }
|
||||
|
||||
|
@ -330,20 +330,15 @@ public static class TextPromptExtensions
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The prompt result type.</typeparam>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <param name="style">The default value style.</param>
|
||||
/// <param name="style">The default value style or <see langword="null"/> to use the default style (green).</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TextPrompt<T> DefaultValueStyle<T>(this TextPrompt<T> obj, Style style)
|
||||
public static TextPrompt<T> DefaultValueStyle<T>(this TextPrompt<T> 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 class TextPromptExtensions
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The prompt result type.</typeparam>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <param name="style">The style to use for displaying the choices.</param>
|
||||
/// <param name="style">The style to use for displaying the choices or <see langword="null"/> to use the default style (blue).</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TextPrompt<T> ChoicesStyle<T>(this TextPrompt<T> obj, Style style)
|
||||
public static TextPrompt<T> ChoicesStyle<T>(this TextPrompt<T> 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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user