SelectionPrompt<>

Represents a single list prompt.

Represents a single list prompt.

Constructors

public SelectionPrompt`1(IEqualityComparer<T> comparer = null)

Initializes a new instance of the SelectionPrompt class.

Parameters:

comparer (IEqualityComparer<T>)
The IEqualityComparer implementation to use when comparing items, or null to use the default IEqualityComparer for the type of the item.

Properties

CancelResult : Func<T>

Gets or sets a Func that will be triggered if Cancel is triggered by the 'ESC' key.

Converter : Func<T, string>

Gets or sets the converter to get the display string for a choice. By default the corresponding TypeConverter is used.

DefaultValue : T

Gets or sets the choice to show as selected when the prompt is first displayed. By default the first choice is selected.

Mode : SelectionMode

Gets or sets the selection mode. Defaults to Leaf.

MoreChoicesText : string

Gets or sets the text that will be displayed if there are more choices to show.

PageSize : int

Gets or sets the page size. Defaults to 10.

SearchEnabled : bool

Gets or sets a value indicating whether or not search is enabled.

SearchPlaceholderText : string

Gets or sets the text that will be displayed when no search text has been entered.

Title : string

Gets or sets the title.

WrapAround : bool

Gets or sets a value indicating whether the selection should wrap around when reaching the edge. Defaults to false.

Methods

public ISelectionItem<T> AddChoice(T item)

Adds a choice.

Parameters:

item (T)
The item to add.

Returns:

A ISelectionItem so that multiple calls can be chained.

public T Show(IAnsiConsole console)

Shows the prompt.

Parameters:

console (IAnsiConsole)
The console.

Returns:

The prompt input result.

public Task<T> ShowAsync(IAnsiConsole console, CancellationToken cancellationToken)

Shows the prompt asynchronously.

Parameters:

console (IAnsiConsole)
The console.
cancellationToken (CancellationToken)
The token to monitor for cancellation requests.

Returns:

The prompt input result.

Extension Methods

SelectionPrompt<T> AddCancelResult<T>(this SelectionPrompt<T> obj, T cancelResult)

Sets a Func that will be triggered if the prompt is cancelled with 'ESC'.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> AddCancelResult<T>(this SelectionPrompt<T> obj, Func<T> cancelResultFunc)

Sets the value that will be returned if the prompt is cancelled with 'ESC'.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> AddChoiceGroup<T>(this SelectionPrompt<T> obj, T group, T[] choices)

Adds multiple grouped choices.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> AddChoiceGroup<T>(this SelectionPrompt<T> obj, T group, IEnumerable<T> choices)

Adds multiple grouped choices.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> AddChoices<T>(this SelectionPrompt<T> obj, T[] choices)

Adds multiple choices.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> AddChoices<T>(this SelectionPrompt<T> obj, IEnumerable<T> choices)

Adds multiple choices.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> DisableSearch<T>(this SelectionPrompt<T> obj)

Disables search for the prompt.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> EnableSearch<T>(this SelectionPrompt<T> obj)

Enables search for the prompt.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> Mode<T>(this SelectionPrompt<T> obj, SelectionMode mode)

Sets the selection mode.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> PageSize<T>(this SelectionPrompt<T> obj, int pageSize)

Sets how many choices that are displayed to the user.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> SearchPlaceholderText<T>(this SelectionPrompt<T> obj, string text)

Sets the text that will be displayed when no search text has been entered.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> Title<T>(this SelectionPrompt<T> obj, string title)

Sets the title.

Returns:

The same instance so that multiple calls can be chained.

SelectionPrompt<T> WrapAround<T>(this SelectionPrompt<T> obj, bool shouldWrap)

Sets whether the selection should wrap around when reaching its edges.

Returns:

The same instance so that multiple calls can be chained.