using System;
namespace Spectre.Console;
///
/// A console capable of writing ANSI escape sequences.
///
public static partial class AnsiConsole
{
///
/// Displays a prompt to the user.
///
/// The prompt result type.
/// The prompt to display.
/// The prompt input result.
public static T Prompt(IPrompt prompt)
{
if (prompt is null)
{
throw new ArgumentNullException(nameof(prompt));
}
return prompt.Show(Console);
}
///
/// Displays a prompt to the user.
///
/// The prompt result type.
/// The prompt markup text.
/// The prompt input result.
public static T Ask(string prompt)
{
return new TextPrompt(prompt).Show(Console);
}
///
/// Displays a prompt to the user with a given default.
///
/// The prompt result type.
/// The prompt markup text.
/// The default value.
/// The prompt input result.
public static T Ask(string prompt, T defaultValue)
{
return new TextPrompt(prompt)
.DefaultValue(defaultValue)
.Show(Console);
}
///
/// Displays a prompt with two choices, yes or no.
///
/// The prompt markup text.
/// Specifies the default answer.
/// true if the user selected "yes", otherwise false.
public static bool Confirm(string prompt, bool defaultValue = true)
{
return new ConfirmationPrompt(prompt)
{
DefaultValue = defaultValue,
}
.Show(Console);
}
}