mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-17 17:32:50 +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.
|
/// Displays a prompt with two choices, yes or no.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="prompt">The prompt markup text.</param>
|
/// <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>
|
/// <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>
|
/// </summary>
|
||||||
public char No { get; set; } = 'n';
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the message for invalid choices.
|
/// Gets or sets the message for invalid choices.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -51,7 +56,7 @@ namespace Spectre.Console
|
|||||||
.ValidationErrorMessage(InvalidChoiceMessage)
|
.ValidationErrorMessage(InvalidChoiceMessage)
|
||||||
.ShowChoices(ShowChoices)
|
.ShowChoices(ShowChoices)
|
||||||
.ShowDefaultValue(ShowDefaultValue)
|
.ShowDefaultValue(ShowDefaultValue)
|
||||||
.DefaultValue(Yes)
|
.DefaultValue(DefaultValue ? Yes : No)
|
||||||
.AddChoice(Yes)
|
.AddChoice(Yes)
|
||||||
.AddChoice(No);
|
.AddChoice(No);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user