mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-19 10:12:50 +08:00
Allow Confirmation Prompt Styling (#1210)
* Allow Confirmation Prompt Styling * Remove style null check Co-authored-by: Cédric Luthi <cedric.luthi@gmail.com> * Remove style null coalesce Co-authored-by: Cédric Luthi <cedric.luthi@gmail.com> * Update comment Co-authored-by: Cédric Luthi <cedric.luthi@gmail.com> * Remove style null check Co-authored-by: Cédric Luthi <cedric.luthi@gmail.com> * Update comment Co-authored-by: Cédric Luthi <cedric.luthi@gmail.com> * Remove style null coalesce Co-authored-by: Cédric Luthi <cedric.luthi@gmail.com> --------- Co-authored-by: Cédric Luthi <cedric.luthi@gmail.com>
This commit is contained in:
parent
250b1f4c9c
commit
e07ccd9f66
@ -42,6 +42,23 @@ public static class ConfirmationPromptExtensions
|
|||||||
return ShowChoices(obj, false);
|
return ShowChoices(obj, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the style in which the list of choices is displayed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The confirmation prompt.</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 ConfirmationPrompt ChoicesStyle(this ConfirmationPrompt obj, Style? style)
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.ChoicesStyle = style;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Show or hide the default value.
|
/// Show or hide the default value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -79,6 +96,23 @@ public static class ConfirmationPromptExtensions
|
|||||||
return ShowDefaultValue(obj, false);
|
return ShowDefaultValue(obj, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the style in which the default value is displayed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The confirmation prompt.</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 ConfirmationPrompt DefaultValueStyle(this ConfirmationPrompt obj, Style? style)
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.DefaultValueStyle = style;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the "invalid choice" message for the prompt.
|
/// Sets the "invalid choice" message for the prompt.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -39,6 +39,16 @@ public sealed class ConfirmationPrompt : IPrompt<bool>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ShowDefaultValue { get; set; } = true;
|
public bool ShowDefaultValue { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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. Defaults to blue when <see langword="null"/>.
|
||||||
|
/// </summary>
|
||||||
|
public Style? ChoicesStyle { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the string comparer to use when comparing user input
|
/// Gets or sets the string comparer to use when comparing user input
|
||||||
/// against Yes/No choices.
|
/// against Yes/No choices.
|
||||||
@ -72,8 +82,10 @@ public sealed class ConfirmationPrompt : IPrompt<bool>
|
|||||||
.InvalidChoiceMessage(InvalidChoiceMessage)
|
.InvalidChoiceMessage(InvalidChoiceMessage)
|
||||||
.ValidationErrorMessage(InvalidChoiceMessage)
|
.ValidationErrorMessage(InvalidChoiceMessage)
|
||||||
.ShowChoices(ShowChoices)
|
.ShowChoices(ShowChoices)
|
||||||
|
.ChoicesStyle(ChoicesStyle)
|
||||||
.ShowDefaultValue(ShowDefaultValue)
|
.ShowDefaultValue(ShowDefaultValue)
|
||||||
.DefaultValue(DefaultValue ? Yes : No)
|
.DefaultValue(DefaultValue ? Yes : No)
|
||||||
|
.DefaultValueStyle(DefaultValueStyle)
|
||||||
.AddChoice(Yes)
|
.AddChoice(Yes)
|
||||||
.AddChoice(No);
|
.AddChoice(No);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user