Skip to content

Commit

Permalink
Add confirm to spectre demo and color param for it
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLawrie committed Nov 7, 2023
1 parent 9be1598 commit 95d72d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions PwshSpectreConsole/public/PwshSpectreConsole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ function Read-SpectreConfirm {
[ValidateSet("y", "n")]
[string] $DefaultAnswer = "y",
[string] $ConfirmSuccess,
[string] $ConfirmFailure
[string] $ConfirmFailure,
[ValidateSpectreColor()]
[ArgumentCompletionsSpectreColors()]
[string] $Color = $script:AccentColor.ToMarkup()
)

# This is much fiddlier but it exposes the ability to set the color scheme. The confirmationprompt is just a textprompt with two choices hard coded to y/n:
Expand All @@ -195,7 +198,7 @@ function Read-SpectreConfirm {

# This is how I added the default colors with Set-SpectreColors so you don't have to keep passing them through and get a consistent TUI color scheme
$confirmationPrompt.DefaultValueStyle = [Spectre.Console.Style]::new($script:DefaultValueColor)
$confirmationPrompt.ChoicesStyle = [Spectre.Console.Style]::new($script:AccentColor)
$confirmationPrompt.ChoicesStyle = [Spectre.Console.Style]::new(($Color | Convert-ToSpectreColor))
$confirmationPrompt.InvalidChoiceMessage = "[red]Please select one of the available options[/]"

# Invoke-SpectrePromptAsync supports ctrl-c
Expand Down
7 changes: 7 additions & 0 deletions PwshSpectreConsole/public/PwshSpectreConsoleDemo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ $name = Read-SpectreText "What's your [blue]name[/]?"
$example | Invoke-Expression
Clear-Host

$example = @'
$answer = Read-SpectreConfirm -Prompt "Do you like cute animals?" -DefaultAnswer "y"
'@
$example | Write-SpectreExample -Title "Confirmation" -Description "Confirmation prompts are used to confirm an action or decision before it is executed. They help prevent users from making mistakes or taking actions they did not intend to, reducing the chances of errors and improving the overall user experience."
$example | Invoke-Expression
Clear-Host

$example = @'
$choices = @("Sushi", "Tacos", "Pad Thai", "Lobster", "Falafel", "Chicken Parmesan", "Ramen", "Fish and Chips", "Biryani", "Croissants", "Enchiladas", "Shepherd's Pie", "Gyoza", "Fajitas", "Samosas", "Bruschetta", "Paella", "Hamburger", "Poutine", "Ceviche")
Expand Down

0 comments on commit 95d72d4

Please sign in to comment.