Skip to content

Commit

Permalink
update help and example
Browse files Browse the repository at this point in the history
  • Loading branch information
trackd committed Jan 19, 2024
1 parent 37b6cd7 commit e819d50
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions PwshSpectreConsole/public/prompts/Read-SpectreText.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Read-SpectreText {
:::
.DESCRIPTION
This function uses Spectre Console to prompt the user with a question and returns the user's input. The function takes two parameters: $Question and $DefaultAnswer. $Question is the question to prompt the user with, and $DefaultAnswer is the default answer if the user does not provide any input.
This function uses Spectre Console to prompt the user with a question and returns the user's input.
.PARAMETER Question
The question to prompt the user with.
Expand All @@ -21,9 +21,17 @@ function Read-SpectreText {
.PARAMETER AllowEmpty
If specified, the user can provide an empty answer.
.PARAMETER 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.
.EXAMPLE
# This will prompt the user with the question "What's your name?" and return the user's input. If the user does not provide any input, the function will return "Prefer not to say".
Read-SpectreText -Question "What's your name?" -DefaultAnswer "Prefer not to say"
.EXAMPLE
# This will prompt the user with the question "What's your favorite color?" and return the user's input.
Read-SpectreText -Question "What's your favorite color?" -AnswerColor "Cyan1" -Choices "Black", "Green","Magenta", "I'll never tell!"
#>
[Reflection.AssemblyMetadata("title", "Read-SpectreText")]
param (
Expand All @@ -40,12 +48,11 @@ function Read-SpectreText {
if ($DefaultAnswer) {
$spectrePrompt = [Spectre.Console.TextPromptExtensions]::DefaultValue($spectrePrompt, $DefaultAnswer)
}
if($AnswerColor) {
if ($AnswerColor) {
$spectrePrompt.PromptStyle = [Spectre.Console.Style]::new(($AnswerColor | Convert-ToSpectreColor))
}
$spectrePrompt.AllowEmpty = $AllowEmpty
if ($null -ne $Choices)
{
if ($null -ne $Choices) {
$spectrePrompt = [Spectre.Console.TextPromptExtensions]::AddChoices($spectrePrompt, $Choices)
}
return Invoke-SpectrePromptAsync -Prompt $spectrePrompt
Expand Down

0 comments on commit e819d50

Please sign in to comment.