MultiSelectionPrompt<>

Represents a multi selection list prompt.

Represents a multi selection list prompt.

Constructors

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

Initializes a new instance of the MultiSelectionPrompt 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<List<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.

InstructionsText : string

Gets or sets the text that instructs the user of how to select items.

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.

Required : bool

Gets or sets a value indicating whether or not at least one selection is required.

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 IMultiSelectionItem<T> AddChoice(T item)

Adds a choice.

Parameters:

item (T)
The item to add.

Returns:

A IMultiSelectionItem so that multiple calls can be chained.

public T GetParent(T item)

Returns the parent item of the given item.

Parameters:

item (T)
The item for which to find the parent.

Returns:

The parent item, or null if the given item has no parent.

public IEnumerable<T> GetParents(T item)

Returns all parent items of the given item.

Parameters:

item (T)
The item for which to find the parents.

Returns:

The parent items, or an empty list, if the given item has no parents.

public List<T> Show(IAnsiConsole console)

Shows the prompt.

Parameters:

console (IAnsiConsole)
The console.

Returns:

The prompt input result.

public Task<List<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

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

Adds multiple grouped choices.

Returns:

The same instance so that multiple calls can be chained.

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

Adds multiple grouped choices.

Returns:

The same instance so that multiple calls can be chained.

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

Adds multiple choices.

Returns:

The same instance so that multiple calls can be chained.

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

Adds multiple choices.

Returns:

The same instance so that multiple calls can be chained.

MultiSelectionPrompt<T> AddChoices<T>(this MultiSelectionPrompt<T> obj, T choice, Action<IMultiSelectionItem<T>> configurator)

Adds a choice.

Returns:

The same instance so that multiple calls can be chained.

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

Sets the selection mode.

Returns:

The same instance so that multiple calls can be chained.

MultiSelectionPrompt<T> PageSize<T>(this MultiSelectionPrompt<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.

MultiSelectionPrompt<T> Select<T>(this MultiSelectionPrompt<T> obj, T item)

Marks an item as selected.

Returns:

The same instance so that multiple calls can be chained.

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

Sets the title.

Returns:

The same instance so that multiple calls can be chained.

MultiSelectionPrompt<T> WrapAround<T>(this MultiSelectionPrompt<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.