mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 00:42:51 +08:00
Make default answer for confirmation prompt configurable
This commit is contained in:
parent
04d0e663d5
commit
ed0fb29be4
@ -38,10 +38,15 @@ namespace Spectre.Console
|
||||
/// Displays a prompt with two choices, yes or no.
|
||||
/// </summary>
|
||||
/// <param name="prompt">The prompt markup text.</param>
|
||||
/// <param name="defaultValue">Specifies the default answer.</param>
|
||||
/// <returns><c>true</c> if the user selected "yes", otherwise <c>false</c>.</returns>
|
||||
public static bool Confirm(string prompt)
|
||||
public static bool Confirm(string prompt, bool defaultValue = true)
|
||||
{
|
||||
return new ConfirmationPrompt(prompt).Show(Console);
|
||||
return new ConfirmationPrompt(prompt)
|
||||
{
|
||||
DefaultValue = defaultValue,
|
||||
}
|
||||
.Show(Console);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,11 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
public char No { get; set; } = 'n';
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether "yes" is the default answer.
|
||||
/// </summary>
|
||||
public bool DefaultValue { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the message for invalid choices.
|
||||
/// </summary>
|
||||
@ -51,7 +56,7 @@ namespace Spectre.Console
|
||||
.ValidationErrorMessage(InvalidChoiceMessage)
|
||||
.ShowChoices(ShowChoices)
|
||||
.ShowDefaultValue(ShowDefaultValue)
|
||||
.DefaultValue(Yes)
|
||||
.DefaultValue(DefaultValue ? Yes : No)
|
||||
.AddChoice(Yes)
|
||||
.AddChoice(No);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user