namespace Spectre.Console
{
///
/// A prompt that is answered with a yes or no.
///
public sealed class ConfirmationPrompt : IPrompt
{
private readonly string _prompt;
///
/// Gets or sets the character that represents "yes".
///
public char Yes { get; set; } = 'y';
///
/// Gets or sets the character that represents "no".
///
public char No { get; set; } = 'n';
///
/// Gets or sets the message for invalid choices.
///
public string InvalidChoiceMessage { get; set; } = "[red]Please select one of the available options[/]";
///
/// Gets or sets a value indicating whether or not
/// choices should be shown.
///
public bool ShowChoices { get; set; } = true;
///
/// Gets or sets a value indicating whether or not
/// default values should be shown.
///
public bool ShowDefaultValue { get; set; } = true;
///
/// Initializes a new instance of the class.
///
/// The prompt markup text.
public ConfirmationPrompt(string prompt)
{
_prompt = prompt ?? throw new System.ArgumentNullException(nameof(prompt));
}
///
public bool Show(IAnsiConsole console)
{
var prompt = new TextPrompt(_prompt)
.InvalidChoiceMessage(InvalidChoiceMessage)
.ValidationErrorMessage(InvalidChoiceMessage)
.ShowChoices(ShowChoices)
.ShowDefaultValue(ShowDefaultValue)
.DefaultValue(Yes)
.AddChoice(Yes)
.AddChoice(No);
var result = prompt.Show(console);
return result == Yes;
}
}
}