mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-19 10:12:50 +08:00
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System;
|
|
|
|
namespace Spectre.Console
|
|
{
|
|
/// <summary>
|
|
/// Contains extension methods for <see cref="IAnsiConsole"/>.
|
|
/// </summary>
|
|
public static partial class AnsiConsoleExtensions
|
|
{
|
|
/// <summary>
|
|
/// Displays a prompt to the user.
|
|
/// </summary>
|
|
/// <typeparam name="T">The prompt result type.</typeparam>
|
|
/// <param name="console">The console.</param>
|
|
/// <param name="prompt">The prompt to display.</param>
|
|
/// <returns>The prompt input result.</returns>
|
|
public static T Prompt<T>(this IAnsiConsole console, IPrompt<T> prompt)
|
|
{
|
|
if (prompt is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(prompt));
|
|
}
|
|
|
|
return prompt.Show(console);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Displays a prompt to the user.
|
|
/// </summary>
|
|
/// <typeparam name="T">The prompt result type.</typeparam>
|
|
/// <param name="console">The console.</param>
|
|
/// <param name="prompt">The prompt markup text.</param>
|
|
/// <returns>The prompt input result.</returns>
|
|
public static T Ask<T>(this IAnsiConsole console, string prompt)
|
|
{
|
|
return new TextPrompt<T>(prompt).Show(console);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Displays a prompt with two choices, yes or no.
|
|
/// </summary>
|
|
/// <param name="console">The console.</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>
|
|
public static bool Confirm(this IAnsiConsole console, string prompt, bool defaultValue = true)
|
|
{
|
|
return new ConfirmationPrompt(prompt)
|
|
{
|
|
DefaultValue = defaultValue,
|
|
}
|
|
.Show(console);
|
|
}
|
|
}
|
|
}
|