Skip to content

Read-SpectreSelectionGrouped

Description

This function displays a selection prompt using Spectre Console. The user can select an option from the list of choices provided. The function returns the selected option.
With the -EnableSearch switch, the user can search for choices in the selection prompt by typing the characters instead of just typing up and down arrows.


Examples

Example 1
This example demonstrates a selection prompt with a custom title and choices.

Terminal window
$choices = @{
"Reds" = @("Crimson", "Ruby", "Scarlet")
"Greens" = @("Lime", "Emerald", "Jade")
"Blues" = @("Azure", "Cerulean", "Sapphire")
}
$color = Read-SpectreSelectionGrouped -Message "Select your favorite color" -Choices $choices -Color "Green"
# Type "↓", "↓", "↓", "↓", "↲" to wrap around the list and choose green
Write-SpectreHost "Your chosen color is '$color'"

Parameters

Message

The title of the selection prompt.

TypeRequiredPositionPipelineInputAliases
[String]false1falseTitle
Question
Prompt

Choices

TypeRequiredPositionPipelineInput
[Hashtable]true2false

ChoiceLabelProperty

If the object is complex then the property of the choice object to use as the label in the selection prompt is required.

TypeRequiredPositionPipelineInput
[String]false3false

Color

The color of the selected option in the selection prompt.

TypeRequiredPositionPipelineInput
[Color]false4false

PageSize

The number of choices to display per page in the selection prompt.

TypeRequiredPositionPipelineInput
[Int32]false5false

EnableSearch

If this switch is present, the user can search for choices in the selection prompt by typing the characters instead of just typing up and down arrows.

TypeRequiredPositionPipelineInput
[Switch]falsenamedfalse

TimeoutSeconds

TypeRequiredPositionPipelineInput
[Int32]false6false

SearchHighlightColor

The color of the search highlight in the selection prompt. Defaults to a slightly brighter version of the accent color.

TypeRequiredPositionPipelineInput
[Color]false7false

Syntax

Terminal window
Read-SpectreSelectionGrouped [[-Message] <String>] [-Choices] <Hashtable> [[-ChoiceLabelProperty] <String>] [[-Color] <Color>] [[-PageSize] <Int32>] [-EnableSearch] [[-TimeoutSeconds] <Int32>] [[-SearchHighlightColor] <Color>] [<CommonParameters>]