Read-SpectreText
Description
This function uses Spectre Console to prompt the user with a question and returns the user’s input.
Examples
Example 1
This example demonstrates a simple text prompt with a default answer.
$name = Read-SpectreText -Message "What's your name?" -DefaultAnswer "Prefer not to say"
# Type "↲" to provide no answer
Write-SpectreHost "Your name is '$name'"
Example 2
This example demonstrates a simple text prompt with a default answer and a color.
$favouriteColor = Read-SpectreText -Message "What's your favorite color?" -DefaultAnswer "pink"
# Type "orange", "↲" to enter your favourite color
Write-SpectreHost "Your favourite color is '$favouriteColor'"
Example 3
This example demonstrates a simple text prompt with a default answer, a color, and a list of choices.
$favouriteColor = Read-SpectreText -Message "What's your favorite color?" -AnswerColor "Cyan1" -Choices "Black", "Green", "Magenta", "I'll never tell!"
# Type "orange", "↲", "magenta", "↲" to enter text that must match a choice in the choices list, orange will be rejected, magenta will be accepted
Write-SpectreHost "Your favourite color is '$favouriteColor'"
Parameters
Message
The question to prompt the user with.
Type | Required | Position | PipelineInput | Aliases |
---|---|---|---|---|
[String] | true | 1 | false | Title Question Prompt |
DefaultAnswer
The default answer if the user does not provide any input.
Type | Required | Position | PipelineInput |
---|---|---|---|
[String] | false | 2 | false |
AnswerColor
The color of the user’s answer input. The default behaviour uses the standard terminal text color.
Type | Required | Position | PipelineInput |
---|---|---|---|
[Color] | false | 3 | false |
AllowEmpty
If specified, the user can provide an empty answer.
Type | Required | Position | PipelineInput |
---|---|---|---|
[Switch] | false | named | false |
TimeoutSeconds
Type | Required | Position | PipelineInput |
---|---|---|---|
[Int32] | false | 4 | false |
Choices
An array of choices that the user can choose from. If specified, the user will be prompted with a list of choices to choose from, with validation. With autocomplete and can tab through the choices.
Type | Required | Position | PipelineInput |
---|---|---|---|
[String[]] | false | 5 | false |
Syntax
Read-SpectreText [-Message] <String> [[-DefaultAnswer] <String>] [[-AnswerColor] <Color>] [-AllowEmpty] [[-TimeoutSeconds] <Int32>] [[-Choices] <String[]>] [<CommonParameters>]