mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00

committed by
Phil Scott

parent
c147929f16
commit
315a52f3e9
@ -9,20 +9,21 @@ namespace Spectre.Console
|
||||
public static class SelectionPromptExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a choice.
|
||||
/// Sets the selection mode.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The prompt result type.</typeparam>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <param name="choice">The choice to add.</param>
|
||||
/// <param name="mode">The selection mode.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> AddChoice<T>(this SelectionPrompt<T> obj, T choice)
|
||||
public static SelectionPrompt<T> Mode<T>(this SelectionPrompt<T> obj, SelectionMode mode)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Choices.Add(choice);
|
||||
obj.Mode = mode;
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -34,13 +35,18 @@ namespace Spectre.Console
|
||||
/// <param name="choices">The choices to add.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> AddChoices<T>(this SelectionPrompt<T> obj, params T[] choices)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Choices.AddRange(choices);
|
||||
foreach (var choice in choices)
|
||||
{
|
||||
obj.AddChoice(choice);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -52,13 +58,43 @@ namespace Spectre.Console
|
||||
/// <param name="choices">The choices to add.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> AddChoices<T>(this SelectionPrompt<T> obj, IEnumerable<T> choices)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Choices.AddRange(choices);
|
||||
foreach (var choice in choices)
|
||||
{
|
||||
obj.AddChoice(choice);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds multiple grouped choices.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The prompt result type.</typeparam>
|
||||
/// <param name="obj">The prompt.</param>
|
||||
/// <param name="group">The group.</param>
|
||||
/// <param name="choices">The choices to add.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> AddChoiceGroup<T>(this SelectionPrompt<T> obj, T group, IEnumerable<T> choices)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
var root = obj.AddChoice(group);
|
||||
foreach (var choice in choices)
|
||||
{
|
||||
root.AddChild(choice);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -70,6 +106,7 @@ namespace Spectre.Console
|
||||
/// <param name="title">The title markup text.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> Title<T>(this SelectionPrompt<T> obj, string? title)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
@ -88,6 +125,7 @@ namespace Spectre.Console
|
||||
/// <param name="pageSize">The number of choices that are displayed to the user.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> PageSize<T>(this SelectionPrompt<T> obj, int pageSize)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
@ -111,6 +149,7 @@ namespace Spectre.Console
|
||||
/// <param name="highlightStyle">The highlight style of the selected choice.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> HighlightStyle<T>(this SelectionPrompt<T> obj, Style highlightStyle)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
@ -129,6 +168,7 @@ namespace Spectre.Console
|
||||
/// <param name="text">The text to display.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> MoreChoicesText<T>(this SelectionPrompt<T> obj, string? text)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
@ -147,6 +187,7 @@ namespace Spectre.Console
|
||||
/// <param name="displaySelector">The function to get a display string for a given choice.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static SelectionPrompt<T> UseConverter<T>(this SelectionPrompt<T> obj, Func<T, string>? displaySelector)
|
||||
where T : notnull
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
|
Reference in New Issue
Block a user