Skip to content

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.

Terminal window
$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.

Terminal window
$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.

Terminal window
$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.

TypeRequiredPositionPipelineInputAliases
[String]true1falseTitle
Question
Prompt

DefaultAnswer

The default answer if the user does not provide any input.

TypeRequiredPositionPipelineInput
[String]false2false

AnswerColor

The color of the user’s answer input. The default behaviour uses the standard terminal text color.

TypeRequiredPositionPipelineInput
[Color]false3false

AllowEmpty

If specified, the user can provide an empty answer.

TypeRequiredPositionPipelineInput
[Switch]falsenamedfalse

TimeoutSeconds

TypeRequiredPositionPipelineInput
[Int32]false4false

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.

TypeRequiredPositionPipelineInput
[String[]]false5false

Syntax

Terminal window
Read-SpectreText [-Message] <String> [[-DefaultAnswer] <String>] [[-AnswerColor] <Color>] [-AllowEmpty] [[-TimeoutSeconds] <Int32>] [[-Choices] <String[]>] [<CommonParameters>]