Skip to content

Commit

Permalink
Allow passing a nullable style in DefaultValueStyle() and ChoicesStyle()
Browse files Browse the repository at this point in the history
This will allow to slightly simplify the implementation of #1210

See also related discussion on #1349 (comment)
  • Loading branch information
0xced authored and patriksvensson committed Nov 10, 2023
1 parent 29a4368 commit 4219bbb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Spectre.Console/Prompts/TextPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
18 changes: 4 additions & 14 deletions src/Spectre.Console/Prompts/TextPromptExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,15 @@ public static TextPrompt<T> WithConverter<T>(this TextPrompt<T> obj, Func<T, str
/// </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;
}
Expand All @@ -353,20 +348,15 @@ public static TextPrompt<T> DefaultValueStyle<T>(this TextPrompt<T> obj, Style s
/// </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;
}
Expand Down

0 comments on commit 4219bbb

Please sign in to comment.