Read-SpectreMultiSelection
Description
This function displays a multi-selection prompt using Spectre Console and returns the selected choices. The prompt allows the user to select one or more choices from a list of options. The function supports customizing the title, choices, choice label property, color, and page size of the prompt.
Examples
Example 1
This example demonstrates a multi-selection prompt with a custom title and choices.
$fruits = Read-SpectreMultiSelection -Message "Select your favourite fruits" ` -Choices @("apple", "banana", "orange", "pear", "strawberry", "durian", "lemon") ` -PageSize 4# Type "↓", "<space>", "↓", "↓", "<space>", "↓", "<space>", "↲" to choose banana, pear and strawberryWrite-SpectreHost "Your favourite fruits are $($fruits -join ', ')"
Example 2
This example demonstrates using pipeline input to provide choices for multi-selection.
$selectedFiles = @("file1.db", "file2.db", "file3.db") | ForEach-Object { [PSCustomObject]@{ Name = $_ } } | Read-SpectreMultiSelection -Message "Select database files to backup" -ChoiceLabelProperty Name# Type "<space>", "↓", "<space>", "↲" to select multiple filesWrite-SpectreHost "Selected files: $($selectedFiles.Name -join ', ')"
Parameters
Message
The title of the prompt. Defaults to “What are your favourite [Spectre.Console.Color]?”.
Type | Required | Position | PipelineInput | Aliases |
---|---|---|---|---|
[String] | false | named | false | Title Question Prompt |
Choices
The list of choices to display in the selection prompt. ChoiceLabelProperty is required if the choices are complex objects rather than an array of strings.
Type | Required | Position | PipelineInput |
---|---|---|---|
[Array] | true | 2 | true (ByValue) |
ChoiceLabelProperty
If the object is complex then the property of the choice object to use as the label in the selection prompt is required.
Type | Required | Position | PipelineInput |
---|---|---|---|
[String] | false | named | false |
Color
The color to use for highlighting the selected choices. Defaults to the accent color of the script.
Type | Required | Position | PipelineInput |
---|---|---|---|
[Color] | false | named | false |
PageSize
The number of choices to display per page. Defaults to 5.
Type | Required | Position | PipelineInput |
---|---|---|---|
[Int32] | false | named | false |
TimeoutSeconds
Type | Required | Position | PipelineInput |
---|---|---|---|
[Int32] | false | named | false |
AllowEmpty
Allow the multi-selection to be submitted without any options chosen.
Type | Required | Position | PipelineInput |
---|---|---|---|
[Switch] | false | named | false |
Syntax
Read-SpectreMultiSelection [-Message <String>] [-Choices] <Array> [-ChoiceLabelProperty <String>] [-Color <Color>] [-PageSize <Int32>] [-TimeoutSeconds <Int32>] [-AllowEmpty] [<CommonParameters>]