From 469d4e290144eed77d5fbe703dda55625d0483b9 Mon Sep 17 00:00:00 2001 From: Shaun Lawrie Date: Mon, 27 Nov 2023 23:27:06 +1300 Subject: [PATCH] Colors. emoji and start of unit tests --- PwshSpectreConsole.Docs/UpdateDocs.ps1 | 9 +- .../reference/Demo/Get-SpectreDemoColors.md | 62 ++++++++++++++ .../reference/Demo/Get-SpectreDemoEmoji.md | 62 ++++++++++++++ .../docs/reference/Demo/Start-SpectreDemo.md | 43 ++++++++++ .../Formatting/Format-SpectrePanel.md | 11 +++ .../Formatting/Format-SpectreTable.md | 23 ++++++ .../Formatting/Format-SpectreTree.md | 11 ++- .../New-SpectreChartItem.md | 0 .../Invoke-SpectreCommandWithStatus.md | 82 ++++++++++++++++++- .../Invoke-SpectreScriptBlockQuietly.md | 3 +- .../Format-SpectreBarChart.tests.ps1 | 37 +++++++++ PwshSpectreConsole/PwshSpectreConsole.psd1 | 3 +- ...olorDemo.ps1 => Get-SpectreDemoColors.ps1} | 18 ++-- .../public/demo/Get-SpectreDemoEmoji.ps1 | 37 +++++++++ .../Invoke-SpectreCommandWithStatus.ps1 | 2 +- .../Invoke-SpectreScriptBlockQuietly.ps1 | 3 +- 16 files changed, 389 insertions(+), 17 deletions(-) create mode 100644 PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Get-SpectreDemoColors.md create mode 100644 PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Get-SpectreDemoEmoji.md create mode 100644 PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Start-SpectreDemo.md rename PwshSpectreConsole.Docs/src/content/docs/reference/{Progress => Formatting}/New-SpectreChartItem.md (100%) create mode 100644 PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.tests.ps1 rename PwshSpectreConsole/public/demo/{Get-SpectreColorDemo.ps1 => Get-SpectreDemoColors.ps1} (67%) create mode 100644 PwshSpectreConsole/public/demo/Get-SpectreDemoEmoji.ps1 diff --git a/PwshSpectreConsole.Docs/UpdateDocs.ps1 b/PwshSpectreConsole.Docs/UpdateDocs.ps1 index f0ecdbdc..61c6712d 100644 --- a/PwshSpectreConsole.Docs/UpdateDocs.ps1 +++ b/PwshSpectreConsole.Docs/UpdateDocs.ps1 @@ -10,7 +10,7 @@ Import-Module "$PSScriptRoot\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -For Remove-Item -Recurse -Path "$PSScriptRoot\src\content\docs\reference\*" -Force Get-Module PwshSpectreConsole | Save-MarkdownHelp -OutputPath "$PSScriptRoot\src\content\docs\reference\" -IncludeYamlHeader -YamlHeaderInformationType Metadata -ExcludeFile "*.gif", "*.png" -$new = @("New-SpectreChartItem.md") +$new = @("New-SpectreChartItem.md", "Get-SpectreDemoColors", "Get-SpectreDemoEmoji") $experimental = @("Get-SpectreImageExperimental.md", "Invoke-SpectreScriptBlockQuietly.md") $newTag = @" @@ -30,13 +30,14 @@ sidebar: # Post-processing for astro stuff $groups = @( @{ Name = "Prompts"; Matches = @("read-") } - @{ Name = "Formatting"; Matches = @("format-") } - @{ Name = "Progress"; Matches = @("invoke-", "job", "chartitem") } + @{ Name = "Formatting"; Matches = @("format-", "chartitem") } + @{ Name = "Progress"; Matches = @("invoke-", "job", "spectrescriptblock") } @{ Name = "Images"; Matches = @("image") } @{ Name = "Writing"; Matches = @("write-", "escaped") } @{ Name = "Config"; Matches = @("set-") } + @{ Name = "Demo"; Matches = @("spectredemo") } ) -$remove = @("Start-SpectreDemo.md") + $docs = Get-ChildItem "$PSScriptRoot\src\content\docs\reference\" -Filter "*.md" -Recurse foreach($doc in $docs) { if($remove -contains $doc.Name) { diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Get-SpectreDemoColors.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Get-SpectreDemoColors.md new file mode 100644 index 00000000..4fc43a1b --- /dev/null +++ b/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Get-SpectreDemoColors.md @@ -0,0 +1,62 @@ +--- +title: Get-SpectreDemoColors +--- + + + + + + + +### Synopsis + +Get-SpectreDemoColors + + + + +--- + + +### Description + + +--- + + +### Parameters + + +--- + + +### Inputs +None + + + + +--- + + +### Outputs +* [Object](https://learn.microsoft.com/en-us/dotnet/api/System.Object) + + + + + + +--- + + +### Syntax +```powershell +syntaxItem +``` + +``` +```powershell +{@{name=Get-SpectreDemoColors; CommonParameters=False; parameter=System.Object[]}} +``` + diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Get-SpectreDemoEmoji.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Get-SpectreDemoEmoji.md new file mode 100644 index 00000000..4853c50e --- /dev/null +++ b/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Get-SpectreDemoEmoji.md @@ -0,0 +1,62 @@ +--- +title: Get-SpectreDemoEmoji +--- + + + + + + + +### Synopsis + +Get-SpectreDemoEmoji + + + + +--- + + +### Description + + +--- + + +### Parameters + + +--- + + +### Inputs +None + + + + +--- + + +### Outputs +* [Object](https://learn.microsoft.com/en-us/dotnet/api/System.Object) + + + + + + +--- + + +### Syntax +```powershell +syntaxItem +``` + +``` +```powershell +{@{name=Get-SpectreDemoEmoji; CommonParameters=False; parameter=System.Object[]}} +``` + diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Start-SpectreDemo.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Start-SpectreDemo.md new file mode 100644 index 00000000..99b3a0c9 --- /dev/null +++ b/PwshSpectreConsole.Docs/src/content/docs/reference/Demo/Start-SpectreDemo.md @@ -0,0 +1,43 @@ +--- +title: Start-SpectreDemo +--- + + + + + + + +### Synopsis +Runs a demo of the PwshSpectreConsole module. + + + +--- + + +### Description + +This function runs a demo of the PwshSpectreConsole module, showcasing some of its features. It displays various examples of Spectre.Console functionality wrapped in PowerShell functions, such as text entry, select lists, multi-select lists, and panels. + + + +--- + + +### Examples +Runs the PwshSpectreConsole demo. + +```powershell +PS C:\> Start-SpectreDemo +``` + + +--- + + +### Syntax +```powershell +Start-SpectreDemo [] +``` + diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectrePanel.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectrePanel.md index 8f0b2862..9efdd492 100644 --- a/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectrePanel.md +++ b/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectrePanel.md @@ -73,6 +73,17 @@ The type of border to be displayed around the panel. Valid values are "Rounded", +Valid Values: + +* Ascii +* Double +* Heavy +* None +* Rounded +* Square + + + diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectreTable.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectreTable.md index 84e1c53d..6c65a198 100644 --- a/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectreTable.md +++ b/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectreTable.md @@ -62,6 +62,29 @@ The border style of the table. Default is "Double". +Valid Values: + +* Ascii +* Ascii2 +* AsciiDoubleHead +* Double +* DoubleEdge +* Heavy +* HeavyEdge +* HeavyHead +* Horizontal +* Markdown +* Minimal +* MinimalDoubleHead +* MinimalHeavyHead +* None +* Rounded +* Simple +* SimpleHeavy +* Square + + + diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectreTree.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectreTree.md index af783c51..db8b78c1 100644 --- a/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectreTree.md +++ b/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/Format-SpectreTree.md @@ -74,9 +74,14 @@ The hashtable to format as a tree. -#### **Border** +#### **Guide** -The type of border to use for the tree. Valid values are 'Rounded', 'Heavy', 'Light', 'Double', 'Solid', 'Ascii', and 'None'. Default is 'Rounded'. +Valid Values: + +* Ascii +* BoldLine +* DoubleLine +* Line @@ -111,6 +116,6 @@ The color to use for the tree. This can be a Spectre Console color name or a hex ### Syntax ```powershell -Format-SpectreTree [-Data] [[-Border] ] [[-Color] ] [] +Format-SpectreTree [-Data] [[-Guide] ] [[-Color] ] [] ``` diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/New-SpectreChartItem.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/New-SpectreChartItem.md similarity index 100% rename from PwshSpectreConsole.Docs/src/content/docs/reference/Progress/New-SpectreChartItem.md rename to PwshSpectreConsole.Docs/src/content/docs/reference/Formatting/New-SpectreChartItem.md diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/Invoke-SpectreCommandWithStatus.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/Invoke-SpectreCommandWithStatus.md index dea5f83e..df4b5bfa 100644 --- a/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/Invoke-SpectreCommandWithStatus.md +++ b/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/Invoke-SpectreCommandWithStatus.md @@ -58,6 +58,86 @@ The type of spinner to display. Valid values are "dots", "dots2", "dots3", "dots +Valid Values: + +* Aesthetic +* Arc +* Arrow +* Arrow2 +* Arrow3 +* Ascii +* Balloon +* Balloon2 +* BetaWave +* Bounce +* BouncingBall +* BouncingBar +* BoxBounce +* BoxBounce2 +* Christmas +* Circle +* CircleHalves +* CircleQuarters +* Clock +* Default +* Dots +* Dots10 +* Dots11 +* Dots12 +* Dots2 +* Dots3 +* Dots4 +* Dots5 +* Dots6 +* Dots7 +* Dots8 +* Dots8Bit +* Dots9 +* Dqpb +* Earth +* Flip +* Grenade +* GrowHorizontal +* GrowVertical +* Hamburger +* Hearts +* Layer +* Line +* Line2 +* Material +* Monkey +* Moon +* Noise +* Pipe +* Point +* Pong +* Runner +* Shark +* SimpleDots +* SimpleDotsScrolling +* Smiley +* SquareCorners +* Squish +* Star +* Star2 +* Toggle +* Toggle10 +* Toggle11 +* Toggle12 +* Toggle13 +* Toggle2 +* Toggle3 +* Toggle4 +* Toggle5 +* Toggle6 +* Toggle7 +* Toggle8 +* Toggle9 +* Triangle +* Weather + + + @@ -84,7 +164,7 @@ The title to display above the spinner. #### **Color** -The color of the spinner. Valid values are "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "brightRed", "brightGreen", "brightYellow", "brightBlue", "brightMagenta", "brightCyan", "brightWhite". +The color of the spinner. Valid values can be found with Get-SpectreDemoColors. diff --git a/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/Invoke-SpectreScriptBlockQuietly.md b/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/Invoke-SpectreScriptBlockQuietly.md index 654b22d2..6165163d 100644 --- a/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/Invoke-SpectreScriptBlockQuietly.md +++ b/PwshSpectreConsole.Docs/src/content/docs/reference/Progress/Invoke-SpectreScriptBlockQuietly.md @@ -13,7 +13,8 @@ title: Invoke-SpectreScriptBlockQuietly ### Synopsis -A testing function for invoking a script block in a background job inside Invoke-SpectreCommandWithProgress to help with https://github.com/ShaunLawrie/PwshSpectreConsole/issues/7 +This is a test function for invoking a script block in a background job inside Invoke-SpectreCommandWithProgress to help with https://github.com/ShaunLawrie/PwshSpectreConsole/issues/7 +Some commands cause output that interferes with the progress bar, this function is an attempt to suppress that output when all other attempts have failed. :::caution This is experimental. ::: diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.tests.ps1 new file mode 100644 index 00000000..43473417 --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.tests.ps1 @@ -0,0 +1,37 @@ +# Import the module to be tested/ +BeforeAll { + Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psm1" -Force +} + +Describe "Format-SpectreBarChart" { + Context "WhenThingsHappen" { + BeforeEach { + Mock Write-AnsiConsole { + Write-Host "FUUUCK" + } + + Mock Convert-ToSpectreColor { + Write-Host "FUUUCK2" + } + } + + It "Should create a bar chart with correct width" { + $data = @( + @{ Label = "Apples"; Value = 10; Color = "Green" }, + @{ Label = "Oranges"; Value = 5; Color = "Yellow" }, + @{ Label = "Bananas"; Value = 3; Color = "Red" } + ) + Format-SpectreBarChart -Data $data -Title "Fruit Sales" -Width 50 + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should handle single item data correctly" { + Mock Write-AnsiConsole { + Write-Host "FUUUCK1" + } + $data = @{ Label = "Apples"; Value = 10; Color = "Green" } + Format-SpectreBarChart -Data $data -Title "Fruit Sales" -Width 50 + Assert-MockCalled Write-AnsiConsole -Times 1 -Exactly + } + } +} \ No newline at end of file diff --git a/PwshSpectreConsole/PwshSpectreConsole.psd1 b/PwshSpectreConsole/PwshSpectreConsole.psd1 index ef3663a0..0e049117 100644 --- a/PwshSpectreConsole/PwshSpectreConsole.psd1 +++ b/PwshSpectreConsole/PwshSpectreConsole.psd1 @@ -82,7 +82,8 @@ FunctionsToExport = 'Add-SpectreJob', 'Format-SpectreBarChart', 'Read-SpectreSelection', 'Read-SpectreText', 'Set-SpectreColors', 'Start-SpectreDemo', 'Wait-SpectreJobs', 'Write-SpectreFigletText', 'Write-SpectreHost', 'Write-SpectreRule', 'Read-SpectreConfirm', - 'New-SpectreChartItem', 'Invoke-SpectreScriptBlockQuietly' + 'New-SpectreChartItem', 'Invoke-SpectreScriptBlockQuietly', + 'Get-SpectreDemoColors', 'Get-SpectreDemoEmoji' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/PwshSpectreConsole/public/demo/Get-SpectreColorDemo.ps1 b/PwshSpectreConsole/public/demo/Get-SpectreDemoColors.ps1 similarity index 67% rename from PwshSpectreConsole/public/demo/Get-SpectreColorDemo.ps1 rename to PwshSpectreConsole/public/demo/Get-SpectreDemoColors.ps1 index 7948b30e..f5be8e54 100644 --- a/PwshSpectreConsole/public/demo/Get-SpectreColorDemo.ps1 +++ b/PwshSpectreConsole/public/demo/Get-SpectreDemoColors.ps1 @@ -1,7 +1,11 @@ -function Get-SpectreColorDemo { - [Reflection.AssemblyMetadata("title", "Start-SpectreDemo")] +function Get-SpectreDemoColors { + [Reflection.AssemblyMetadata("title", "Get-SpectreDemoColors")] param () + Write-Host "" + Write-SpectreRule "Colors" + Write-Host "" + $colors = [Spectre.Console.Color] | Get-Member -Static -Type Properties | Select-Object -ExpandProperty Name $colors = $colors | ForEach-Object { $prefix = ($_ -replace '[_0-9]+', '') @@ -37,8 +41,12 @@ function Get-SpectreColorDemo { Write-SpectreHost ("[$color]$color[/]") } - Write-Host "`nThe colors can be passed as the -Color parameter for most commands or used in Spectre Console markup like so:`n" - Write-Host " Input: I am [Red]colored text[/] using [Yellow1 on Turquoise4]Spectre markdown[/]!" - Write-SpectreHost " Output: I am [Red]colored text[/] using [Yellow1 on Turquoise4]Spectre markdown[/]!" + Write-Host "" + Write-SpectreRule "Help" + Write-Host "" + + Write-Host "The colors can be passed as the `"-Color`" parameter for most commands or used in Spectre Console markup like so:`n" + Write-SpectreHost " PS> [Yellow]Write-SpectreHost[/] [DeepSkyBlue1]`"$('I am [Red]colored text[/] using [Yellow1 on Turquoise4]Spectre markdown[/]!' | Get-SpectreEscapedText)`"[/]" + Write-SpectreHost " [white on grey19]I am [Red]colored text[/] using [Yellow1 on Turquoise4]Spectre markdown[/]! [/]" Write-SpectreHost "`nFor more markdown hints see [link]https://spectreconsole.net/markup[/]`n" } \ No newline at end of file diff --git a/PwshSpectreConsole/public/demo/Get-SpectreDemoEmoji.ps1 b/PwshSpectreConsole/public/demo/Get-SpectreDemoEmoji.ps1 new file mode 100644 index 00000000..f539ab60 --- /dev/null +++ b/PwshSpectreConsole/public/demo/Get-SpectreDemoEmoji.ps1 @@ -0,0 +1,37 @@ +function Get-SpectreDemoEmoji { + [Reflection.AssemblyMetadata("title", "Get-SpectreDemoEmoji")] + param () + + Write-Host "" + Write-SpectreRule "`nGeneral" + Write-Host "" + + $emojiCollection = [Spectre.Console.Emoji+Known] | Get-Member -Static -Type Properties | Select-Object -ExpandProperty Name + $faces = @() + foreach($emoji in $emojiCollection) { + $id = ($emoji -creplace '([A-Z])', '_$1' -replace '^_', '').ToLower() + if($id -like "*face*") { + $faces += $id + } else { + Write-SpectreHost ":${id}:`t$id" + } + } + + Write-Host "" + Write-SpectreRule "Faces" + Write-Host "" + foreach($face in $faces) { + Write-SpectreHost ":${face}:`t$face" + } + + Write-Host "" + Write-SpectreRule "Help" + Write-Host "" + Write-Host "The emoji can be used in Spectre Console markup like so:`n" + # Apparently there is no way to escape emoji codes https://github.com/spectreconsole/spectre.console/issues/408 + Write-SpectreHost -NoNewline " PS> [yellow]Write-Host[/] [DeepSkyBlue1]`"I am a :[/]" + Write-SpectreHost -NoNewline "[DeepSkyBlue1]grinning_face: Spectre markdown emoji string :[/]" + Write-SpectreHost "[DeepSkyBlue1]victory_hand: !`"[/]" + Write-SpectreHost " [white on grey19]I am a :grinning_face: Spectre markdown emoji string :victory_hand: ! [/]" + Write-SpectreHost "`nEmoji support is dependent on OS, terminal & font support. For more markdown hints see [link]https://spectreconsole.net/markup[/] and for more emoji help see [link]https://spectreconsole.net/appendix/emojis[/]`n" +} \ No newline at end of file diff --git a/PwshSpectreConsole/public/progress/Invoke-SpectreCommandWithStatus.ps1 b/PwshSpectreConsole/public/progress/Invoke-SpectreCommandWithStatus.ps1 index b6133a81..52aa576a 100644 --- a/PwshSpectreConsole/public/progress/Invoke-SpectreCommandWithStatus.ps1 +++ b/PwshSpectreConsole/public/progress/Invoke-SpectreCommandWithStatus.ps1 @@ -18,7 +18,7 @@ function Invoke-SpectreCommandWithStatus { The title to display above the spinner. .PARAMETER Color - The color of the spinner. Valid values can be found with Get-SpectreColorDemo. + The color of the spinner. Valid values can be found with Get-SpectreDemoColors. .EXAMPLE # Starts a Spectre status spinner with the "dots" spinner type, a yellow color, and the title "Waiting for process to complete". The spinner will continue to spin for 5 seconds. diff --git a/PwshSpectreConsole/public/progress/Invoke-SpectreScriptBlockQuietly.ps1 b/PwshSpectreConsole/public/progress/Invoke-SpectreScriptBlockQuietly.ps1 index 9686fcf4..6a2e45ad 100644 --- a/PwshSpectreConsole/public/progress/Invoke-SpectreScriptBlockQuietly.ps1 +++ b/PwshSpectreConsole/public/progress/Invoke-SpectreScriptBlockQuietly.ps1 @@ -1,6 +1,7 @@ <# .SYNOPSIS - A testing function for invoking a script block in a background job inside Invoke-SpectreCommandWithProgress to help with https://github.com/ShaunLawrie/PwshSpectreConsole/issues/7 + This is a test function for invoking a script block in a background job inside Invoke-SpectreCommandWithProgress to help with https://github.com/ShaunLawrie/PwshSpectreConsole/issues/7 + Some commands cause output that interferes with the progress bar, this function is an attempt to suppress that output when all other attempts have failed. :::caution This is experimental. :::