diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreBarChart.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreBarChart.snapshot.txt new file mode 100644 index 00000000..5788ef9c --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreBarChart.snapshot.txt @@ -0,0 +1,3 @@ +Test 1 █████████████████████ 10  +Test 2 █████████████████████████████████████████████ 20  +Test 3 █████████████████████████████████████████████████████████████████████ 30 diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreBreakdownChart.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreBreakdownChart.snapshot.txt new file mode 100644 index 00000000..3a514c85 --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreBreakdownChart.snapshot.txt @@ -0,0 +1,2 @@ +████████████████████████████████████████████████████████████████████████████████ +■ Test 1 10 ■ Test 2 20 ■ Test 3 30 diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreJson.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreJson.snapshot.txt index 2be743e2..f3ce6790 100644 --- a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreJson.snapshot.txt +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreJson.snapshot.txt @@ -1,25 +1,25 @@ -╔═Test title═════════════════════════════════════════════════════════════════╗ -║ { ║ -║ "Name": "John", ║ -║ "Age": 25, ║ -║ "City": "New York", ║ -║ "IsEmployed": true, ║ -║ "Salary": 10, ║ -║ "Hobbies": [ ║ -║ "Reading", ║ -║ "Swimming" ║ -║ ], ║ -║ "Address": { ║ -║ "Street": "123 Main St", ║ -║ "City": "New York", ║ -║ "State": "NY", ║ -║ "Deep": { ║ -║ "Nested": "System.Collections.Hashtable" ║ -║ }, ║ -║ "Zip": "10001" ║ -║ } ║ -║ } ║ -║ ║ -║ ║ -║ ║ -╚════════════════════════════════════════════════════════════════════════════╝ +╔═Test title═════════════════════════════════════════════════════════════════╗ +║ { ║ +║ "Name": "John", ║ +║ "Age": 25, ║ +║ "City": "New York", ║ +║ "IsEmployed": true, ║ +║ "Salary": 10, ║ +║ "Hobbies": [ ║ +║ "Reading", ║ +║ "Swimming" ║ +║ ], ║ +║ "Address": { ║ +║ "State": "NY", ║ +║ "City": "New York", ║ +║ "Street": "123 Main St", ║ +║ "Deep": { ║ +║ "Nested": "System.Collections.Hashtable" ║ +║ }, ║ +║ "Zip": "10001" ║ +║ } ║ +║ } ║ +║ ║ +║ ║ +║ ║ +╚════════════════════════════════════════════════════════════════════════════╝ diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectrePanel.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectrePanel.snapshot.txt index f76b67aa..b072a92e 100644 --- a/PwshSpectreConsole.Tests/@snapshots/Format-SpectrePanel.snapshot.txt +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectrePanel.snapshot.txt @@ -1,3 +1,3 @@ -╭─Test title───────────╮ -│ This is a test panel │ -╰──────────────────────╯ +╭─Test title───────────╮ +│ This is a test panel │ +╰──────────────────────╯ diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTable.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTable.snapshot.txt new file mode 100644 index 00000000..2d3e11ee --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTable.snapshot.txt @@ -0,0 +1,7 @@ +╭────────────┬────────┬───────╮ +│ Color │ Name │ Value │ +├────────────┼────────┼───────┤ +│ Turquoise2 │ Test 1 │ 10 │ +│ #ff0000 │ Test 2 │ 20 │ +│ Turquoise2 │ Test 3 │ 30 │ +╰────────────┴────────┴───────╯ diff --git a/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTree.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTree.snapshot.txt new file mode 100644 index 00000000..be540438 --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Format-SpectreTree.snapshot.txt @@ -0,0 +1,7 @@ +Root +┣━━ Child 1 +┃ ┗━━ Grandchild 1 +┃ ┣━━ Great Grandchild 1 +┃ ┣━━ Great Grandchild 2 +┃ ┗━━ Great Grandchild 3 +┗━━ Child 2 diff --git a/PwshSpectreConsole.Tests/@snapshots/Write-SpectreCalendar.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Write-SpectreCalendar.snapshot.txt new file mode 100644 index 00000000..2ba8ae83 --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Write-SpectreCalendar.snapshot.txt @@ -0,0 +1,17 @@ + July 2024 +╭─────┬─────┬─────┬─────┬─────┬─────┬─────╮ +│ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ Sun │ +├─────┼─────┼─────┼─────┼─────┼─────┼─────┤ +│ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ +│ 8 │ 9 │ 10 │ 11 │ 12 │ 13 │ 14 │ +│ 15 │ 16 │ 17 │ 18 │ 19 │ 20 │ 21 │ +│ 22 │ 23 │ 24 │ 25 │ 26 │ 27 │ 28 │ +│ 29 │ 30 │ 31 │ │ │ │ │ +│ │ │ │ │ │ │ │ +╰─────┴─────┴─────┴─────┴─────┴─────┴─────╯ +╭─────────────┬──────┬───────┬─────╮ +│ Description │ Year │ Month │ Day │ +├─────────────┼──────┼───────┼─────┤ +│ Event 1 │ 2022 │ 3 │ 10 │ +│ Event 2 │ 2022 │ 3 │ 20 │ +╰─────────────┴──────┴───────┴─────╯ diff --git a/PwshSpectreConsole.Tests/@snapshots/Write-SpectreFigletText.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Write-SpectreFigletText.snapshot.txt new file mode 100644 index 00000000..f13137da --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Write-SpectreFigletText.snapshot.txt @@ -0,0 +1,6 @@ +  __ _ _ _ _  +  / _| (_) __ _ | | ___ | |_ | |_  +  | |_ | | / _` | | | / _ \ | __| | __| +  | _| | | | (_| | | | | __/ | |_ | |_  +  |_| |_| \__, | |_| \___| \__| \__| +  |___/  diff --git a/PwshSpectreConsole.Tests/@snapshots/Write-SpectreHost.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Write-SpectreHost.snapshot.txt new file mode 100644 index 00000000..5c81229c --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Write-SpectreHost.snapshot.txt @@ -0,0 +1 @@ +Hello, World! 😎 Yay! diff --git a/PwshSpectreConsole.Tests/@snapshots/Write-SpectreRule.snapshot.txt b/PwshSpectreConsole.Tests/@snapshots/Write-SpectreRule.snapshot.txt new file mode 100644 index 00000000..646c1e0e --- /dev/null +++ b/PwshSpectreConsole.Tests/@snapshots/Write-SpectreRule.snapshot.txt @@ -0,0 +1 @@ +───────────────────────────────────────────────────────── yo, this is a test rule ────────────────────────────────────────────────────────── diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.snapshot.compare.txt b/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.snapshot.compare.txt new file mode 100644 index 00000000..5788ef9c --- /dev/null +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.snapshot.compare.txt @@ -0,0 +1,3 @@ +Test 1 █████████████████████ 10  +Test 2 █████████████████████████████████████████████ 20  +Test 3 █████████████████████████████████████████████████████████████████████ 30 diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.tests.ps1 index add7c30a..a8e3de0b 100644 --- a/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.tests.ps1 +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreBarChart.tests.ps1 @@ -7,6 +7,7 @@ Describe "Format-SpectreBarChart" { BeforeEach { $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true $testWidth = Get-Random -Minimum 10 -Maximum 100 $testTitle = "Test Chart $([guid]::NewGuid())" $testData = @() @@ -69,5 +70,24 @@ Describe "Format-SpectreBarChart" { Format-SpectreBarChart -Data $testData Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly } + + It "Should match the snapshot" { + Mock Write-AnsiConsole { + $testConsole.Write($RenderableObject) + } + $testWidth = 120 + Write-Debug "Setting test width to $testWidth" + $testData = @( + (New-SpectreChartItem -Label "Test 1" -Value 10 -Color "Turquoise2"), + (New-SpectreChartItem -Label "Test 2" -Value 20 -Color "#ff0000"), + (New-SpectreChartItem -Label "Test 3" -Value 30 -Color "Turquoise2") + ) + Format-SpectreBarChart -Data $testData + $snapShotComparison = "$PSScriptRoot\..\@snapshots\Format-SpectreBarChart.snapshot.compare.txt" + Set-Content -Path $snapShotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapShotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectreBarChart.snapshot.txt" -AsByteStream + $snapshot | Should -Be $compare + } } } \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreBreakdownChart.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreBreakdownChart.tests.ps1 index c9141867..65ae8c69 100644 --- a/PwshSpectreConsole.Tests/formatting/Format-SpectreBreakdownChart.tests.ps1 +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreBreakdownChart.tests.ps1 @@ -6,6 +6,7 @@ Describe "Format-SpectreBreakdownChart" { InModuleScope "PwshSpectreConsole" { BeforeEach { $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true $testWidth = Get-Random -Minimum 10 -Maximum 100 $testData = @() for($i = 0; $i -lt (Get-Random -Minimum 3 -Maximum 10); $i++) { @@ -53,5 +54,31 @@ Describe "Format-SpectreBreakdownChart" { Format-SpectreBreakdownChart -Data $testData Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly } + + It "Should match the snapshot" { + Mock Write-AnsiConsole { + $testConsole.Write($RenderableObject) + } + $testWidth = 120 + Write-Debug "Setting test width to $testWidth" + $testData = @( + (New-SpectreChartItem -Label "Test 1" -Value 10 -Color "Turquoise2"), + (New-SpectreChartItem -Label "Test 2" -Value 20 -Color "Turquoise2"), + (New-SpectreChartItem -Label "Test 3" -Value 30 -Color "Turquoise2") + ) + Format-SpectreBreakdownChart -Data $testData + $snapShotComparison = "$PSScriptRoot\..\@snapshots\Format-SpectreBreakdownChart.snapshot.compare.txt" + Set-Content -Path $snapShotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapShotComparison -AsByteStream + $snapShot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectreBreakdownChart.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } + } } } \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreJson.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreJson.tests.ps1 index 8db26724..db6f626f 100644 --- a/PwshSpectreConsole.Tests/formatting/Format-SpectreJson.tests.ps1 +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreJson.tests.ps1 @@ -7,6 +7,7 @@ Describe "Format-SpectreJson" { BeforeEach { $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true $testData = @( [pscustomobject]@{ Name = "John" @@ -53,6 +54,9 @@ Describe "Format-SpectreJson" { Mock Get-HostWidth { return 100 } Mock Get-HostHeight { return 100 } + Mock Write-AnsiConsole { + $testConsole.Write($RenderableObject) + } } It "tries to render a panel which somewhat implies that the json parsing worked" { @@ -83,15 +87,63 @@ Describe "Format-SpectreJson" { Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly } + It "Simple scalar array test" { + { + $numbers = Get-Random -Minimum 30 -Maximum 50 + 1..$numbers | Format-SpectreJson -Border None + $json = $testConsole.Output | StripAnsi + ($json.trim() -split "\r?\n").count | Should -Be ($numbers + 2) # 10 items + 2 braces + } | Should -Not -Throw + } + + It "Simple String test" { + { + $numbers = Get-Random -Minimum 30 -Maximum 50 + 1..$numbers | ConvertTo-Json | Format-SpectreJson -Border None + $json = $testConsole.Output | StripAnsi + ($json.trim() -split "\r?\n").count | Should -Be ($numbers + 2) # 10 items + 2 braces + } | Should -Not -Throw + } + + It "Should take json string input" { + $data = @( + [pscustomobject]@{Name = "John"; Age = 25; City = "New York" }, + [pscustomobject]@{Name = "Jane"; Age = $null; City = "Los Angeles" } + ) + $data | ConvertTo-Json | Format-SpectreJson -Border None + $roundtrip = $testConsole.Output | StripAnsi | ConvertFrom-Json + (Compare-Object -ReferenceObject $data -DifferenceObject $roundtrip -Property Name, Age, City -CaseSensitive -IncludeEqual).SideIndicator | Should -Be @('==','==') + } + + It "Should roundtrip json string input" { + $ht = @{} + Get-RandomList -MinItems 30 -MaxItems 50 | ForEach-Object { + $ht[$_] = Get-RandomString + } + $data = [pscustomobject]$ht + $data | ConvertTo-Json | Format-SpectreJson -Border None + $roundtrip = $testConsole.Output | StripAnsi | ConvertFrom-Json + $roundtrip.psobject.properties.name | Should -Be $data.psobject.properties.name + $roundtrip.psobject.properties.value | Should -Be $data.psobject.properties.value + } + It "Should match the snapshot" { Mock Write-AnsiConsole { $testConsole.Write($RenderableObject) } Format-SpectreJson -Title "Test title" -Border "Double" -Color "SpringGreen3" -Height 25 -Width 78 -Data $testData - Set-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectreJson.snapshot.compare.txt" -Value ($testConsole.Output -replace "`r", "") -NoNewline - $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectreJson.snapshot.txt" - $compare = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectreJson.snapshot.txt" - $snapshot | Should -Be $compare + $snapshotComparison = "$PSScriptRoot\..\@snapshots\Format-SpectreJson.snapshot.compare.txt" + Set-Content -Path $snapShotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapshotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectreJson.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } } } } \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectrePanel.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectrePanel.tests.ps1 index e8298f06..a4f37d9e 100644 --- a/PwshSpectreConsole.Tests/formatting/Format-SpectrePanel.tests.ps1 +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectrePanel.tests.ps1 @@ -6,6 +6,7 @@ Describe "Format-SpectrePanel" { InModuleScope "PwshSpectreConsole" { BeforeEach { $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true [Spectre.Console.Testing.TestConsoleExtensions]::Width($testConsole, 80) $testTitle = Get-RandomString -MinimumLength 5 -MaximumLength 10 $testBorder = Get-RandomBoxBorder @@ -47,10 +48,18 @@ Describe "Format-SpectrePanel" { $testConsole.Write($RenderableObject) } Format-SpectrePanel -Data "This is a test panel" -Title "Test title" -Border "Rounded" -Color "Turquoise2" | Out-Null - Set-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectrePanel.snapshot.compare.txt" -Value ($testConsole.Output -replace "`r", "") -NoNewline - $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectrePanel.snapshot.txt" - $compare = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectrePanel.snapshot.txt" - $snapshot | Should -Be $compare + $snapshotComparison = "$PSScriptRoot\..\@snapshots\Format-SpectrePanel.snapshot.compare.txt" + Set-Content -Path $snapshotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapshotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectrePanel.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } } } } \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreTable.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreTable.tests.ps1 index 02e5ff67..0ac5c12d 100644 --- a/PwshSpectreConsole.Tests/formatting/Format-SpectreTable.tests.ps1 +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreTable.tests.ps1 @@ -6,17 +6,21 @@ Describe "Format-SpectreTable" { InModuleScope "PwshSpectreConsole" { BeforeEach { $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + [Spectre.Console.Testing.TestConsoleExtensions]::Width($testConsole, 140) $testData = $null $testBorder = Get-RandomBoxBorder $testColor = Get-RandomColor Mock Write-AnsiConsole { $RenderableObject | Should -BeOfType [Spectre.Console.Table] - $RenderableObject.BorderStyle.Foreground.ToMarkup() | Should -Be $testColor $RenderableObject.Rows.Count | Should -Be $testData.Count if($testBorder -ne "None") { $RenderableObject.Border.GetType().Name | Should -BeLike "*$testBorder*" } + if($testColor) { + $RenderableObject.BorderStyle.Foreground.ToMarkup() | Should -Be $testColor + } $testConsole.Write($RenderableObject) } @@ -121,5 +125,90 @@ Describe "Format-SpectreTable" { $result[0].Length | Should -Be $entryItem[0].Length $result.Count | Should -Be $entryitem.Count } + + It "Should create a table and display results properly" { + $testBorder = 'Markdown' + $testData = Get-ChildItem "$PSScriptRoot" + $verification = $testdata | Format-Table | Get-TableHeader + Format-SpectreTable -Data $testData -Border $testBorder -Color $testColor + $testResult = $testConsole.Output + $rows = $testResult -split "\r?\n" | Select-Object -Skip 1 -SkipLast 2 + $header = $rows[0] + $properties = $header -split '\|' | StripAnsi | ForEach-Object { + if (-Not [String]::IsNullOrWhiteSpace($_)) { + $_.Trim() + } + } + if ($IsLinux -or $IsMacOS) { + $verification.keys | Should -Match 'UnixMode|User|Group|LastWrite|Size|Name' + } + else { + $verification.keys | Should -Be $properties + } + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should create a table and display ICollection results properly" { + $testData = 1 | Group-Object + $testBorder = 'Markdown' + $testColor = $null + Write-Debug "Setting testcolor to $testColor" + Format-SpectreTable -Data $testData -Border $testBorder -HideHeaders -Property Group + $testResult = $testConsole.Output | StripAnsi + $clean = $testResult -replace '\s+|\|' + $clean | Should -Be '{1}' + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should be able to use calculated properties" { + $testData = Get-Process -Id $pid + $testBorder = 'Markdown' + $testColor = $null + Write-Debug "Setting testcolor to $testColor" + $testData | Format-SpectreTable ProcessName, @{Label="TotalRunningTime"; Expression={(Get-Date) - $_.StartTime}} -Border $testBorder + $testResult = $testConsole.Output + $obj = $testResult -split "\r?\n" | Select-Object -Skip 1 -SkipLast 2 + $deconstructed = $obj -split '\|' | StripAnsi | ForEach-Object { + if (-Not [String]::IsNullOrEmpty($_)) { + $_.Trim() + } + } + $deconstructed[0] | Should -Be 'ProcessName' + $deconstructed[1] | Should -Be 'TotalRunningTime' + $deconstructed[4] | Should -Be 'pwsh' + Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly + } + + It "Should match the snapshot" { + Mock Write-AnsiConsole { + $testConsole.Write($RenderableObject) + } + @{ + "Name" = "Test 1" + "Value" = 10 + "Color" = "Turquoise2" + }, @{ + "Name" = "Test 2" + "Value" = 20 + "Color" = "#ff0000" + }, @{ + "Name" = "Test 3" + "Value" = 30 + "Color" = "Turquoise2" + } | Format-SpectreTable -Border "Rounded" -Color "Turquoise2" + + $snapshotComparison = "$PSScriptRoot\..\@snapshots\Format-SpectreTable.snapshot.compare.txt" + Set-Content -Path $snapshotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapshotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectreTable.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } + } } } diff --git a/PwshSpectreConsole.Tests/formatting/Format-SpectreTree.tests.ps1 b/PwshSpectreConsole.Tests/formatting/Format-SpectreTree.tests.ps1 index 773cbbb8..ea37fe84 100644 --- a/PwshSpectreConsole.Tests/formatting/Format-SpectreTree.tests.ps1 +++ b/PwshSpectreConsole.Tests/formatting/Format-SpectreTree.tests.ps1 @@ -6,6 +6,8 @@ Describe "Format-SpectreTree" { InModuleScope "PwshSpectreConsole" { BeforeEach { $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + [Spectre.Console.Testing.TestConsoleExtensions]::Width($testConsole, 140) $testGuide = Get-RandomTreeGuide $testColor = Get-RandomColor @@ -23,5 +25,54 @@ Describe "Format-SpectreTree" { Get-RandomTree | Format-SpectreTree -Guide $testGuide -Color $testColor Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly } + + It "Should match the snapshot" { + Mock Write-AnsiConsole { + $testConsole.Write($RenderableObject) + } + $testData = @{ + Label = "Root" + Children = @( + @{ + Label = "Child 1" + Children = @( + @{ + Label = "Grandchild 1" + Children = @( + @{ + Label = "Great Grandchild 1" + }, + @{ + Label = "Great Grandchild 2" + }, + @{ + Label = "Great Grandchild 3" + } + ) + } + ) + }, + @{ + Label = "Child 2" + } + ) + } + + $testGuide = "BoldLine" + $testColor = "DeepPink2" + $testData | Format-SpectreTree -Guide $testGuide -Color $testColor + $snapshotComparison = "$PSScriptRoot\..\@snapshots\Format-SpectreTree.snapshot.compare.txt" + Set-Content -Path $snapshotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapshotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Format-SpectreTree.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } + } } } \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/formatting/new_Format-SpectreJson.tests.ps1 b/PwshSpectreConsole.Tests/formatting/new_Format-SpectreJson.tests.ps1 deleted file mode 100644 index 491c2060..00000000 --- a/PwshSpectreConsole.Tests/formatting/new_Format-SpectreJson.tests.ps1 +++ /dev/null @@ -1,60 +0,0 @@ -Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue -Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force -Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force - -Describe "Format-SpectreJson" { - InModuleScope "PwshSpectreConsole" { - BeforeEach { - Mock Write-AnsiConsole { - param( - [Parameter(Mandatory)] - [Spectre.Console.Rendering.Renderable] $RenderableObject - ) - try { - $writer = [System.IO.StringWriter]::new() - $output = [Spectre.Console.AnsiConsoleOutput]::new($writer) - $settings = [Spectre.Console.AnsiConsoleSettings]::new() - $settings.Out = $output - $console = [Spectre.Console.AnsiConsole]::Create($settings) - $console.Write($RenderableObject) - $writer.ToString() - } - finally { - $writer.Dispose() - } - } - } - It "Simple scalar array test" { - { - $numbers = Get-Random -Minimum 30 -Maximum 50 - $json = 1..$numbers | Format-SpectreJson -Border None - ($json.trim() -split "\r?\n").count | Should -Be ($numbers + 2) # 10 items + 2 braces - } | Should -Not -Throw - } - It "Simple String test" { - { - $numbers = Get-Random -Minimum 30 -Maximum 50 - $json = 1..$numbers | ConvertTo-Json | Format-SpectreJson -Border None - ($json.trim() -split "\r?\n").count | Should -Be ($numbers + 2) # 10 items + 2 braces - } | Should -Not -Throw - } - It "Should take json string input" { - $data = @( - [pscustomobject]@{Name = "John"; Age = 25; City = "New York" }, - [pscustomobject]@{Name = "Jane"; Age = $null; City = "Los Angeles" } - ) - $roundtrip = $data | ConvertTo-Json | Format-SpectreJson -Border None | StripAnsi | ConvertFrom-Json - (Compare-Object -ReferenceObject $data -DifferenceObject $roundtrip -Property Name, Age, City -CaseSensitive -IncludeEqual).SideIndicator | Should -Be @('==','==') - } - It "Should roundtrip json string input" { - $ht = @{} - Get-RandomList -MinItems 30 -MaxItems 50 | ForEach-Object { - $ht[$_] = Get-RandomString - } - $data = [pscustomobject]$ht - $roundtrip = $data | ConvertTo-Json | Format-SpectreJson -Border None | StripAnsi | ConvertFrom-Json - $roundtrip.psobject.properties.name | Should -Be $data.psobject.properties.name - $roundtrip.psobject.properties.value | Should -Be $data.psobject.properties.value - } - } -} diff --git a/PwshSpectreConsole.Tests/formatting/new_Format-SpectreTable.tests.ps1 b/PwshSpectreConsole.Tests/formatting/new_Format-SpectreTable.tests.ps1 deleted file mode 100644 index 8d7060ec..00000000 --- a/PwshSpectreConsole.Tests/formatting/new_Format-SpectreTable.tests.ps1 +++ /dev/null @@ -1,73 +0,0 @@ -Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue -Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force -Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force - -Describe "Format-SpectreTable" { - InModuleScope "PwshSpectreConsole" { - BeforeEach { - $testBorder = 'Markdown' - $testColor = Get-RandomColor - Write-Debug $testBorder - Write-Debug $testColor - - Mock Write-AnsiConsole { - param( - [Parameter(Mandatory)] - [Spectre.Console.Rendering.Renderable] $RenderableObject - ) - try { - $writer = [System.IO.StringWriter]::new() - $output = [Spectre.Console.AnsiConsoleOutput]::new($writer) - $settings = [Spectre.Console.AnsiConsoleSettings]::new() - $settings.Out = $output - $console = [Spectre.Console.AnsiConsole]::Create($settings) - $console.Write($RenderableObject) - $writer.ToString() - } - finally { - $writer.Dispose() - } - } - } - It "Should create a table and display results properly" { - $testData = Get-ChildItem "$PSScriptRoot" - $verification = $testdata | Format-Table | Get-TableHeader - $testResult = Format-SpectreTable -Data $testData -Border $testBorder -Color $testColor - $rows = $testResult -split "\r?\n" | Select-Object -Skip 1 -SkipLast 2 - $header = $rows[0] - $properties = $header -split '\|' | StripAnsi | ForEach-Object { - if (-Not [String]::IsNullOrWhiteSpace($_)) { - $_.Trim() - } - } - if ($IsLinux -or $IsMacOS) { - $verification.keys | Should -Match 'UnixMode|User|Group|LastWrite|Size|Name' - } - else { - $verification.keys | Should -Be $properties - } - Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly - } - It "Should create a table and display ICollection results properly" { - $testData = 1 | Group-Object - $testResult = Format-SpectreTable -Data $testData -Border Markdown -HideHeaders -Property Group - $clean = $testResult -replace '\s+|\|' - $clean | StripAnsi | Should -Be '{1}' - Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly - } - It "Should be able to use calculated properties" { - $Data = Get-Process -Id $pid - $Format = $data | Format-SpectreTable ProcessName, @{Label="TotalRunningTime"; Expression={(Get-Date) - $_.StartTime}} -Border Markdown - $obj = $Format -split "\r?\n" | Select-Object -Skip 1 -SkipLast 2 - $deconstructed = $obj -split '\|' | StripAnsi | ForEach-Object { - if (-Not [String]::IsNullOrEmpty($_)) { - $_.Trim() - } - } - $deconstructed[0] | Should -Be 'ProcessName' - $deconstructed[1] | Should -Be 'TotalRunningTime' - $deconstructed[4] | Should -Be 'pwsh' - Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly - } - } -} diff --git a/PwshSpectreConsole.Tests/writing/Write-SpectreCalender.tests.ps1 b/PwshSpectreConsole.Tests/writing/Write-SpectreCalender.tests.ps1 index adab3896..3f34aeee 100644 --- a/PwshSpectreConsole.Tests/writing/Write-SpectreCalender.tests.ps1 +++ b/PwshSpectreConsole.Tests/writing/Write-SpectreCalender.tests.ps1 @@ -5,32 +5,21 @@ Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force Describe "Write-SpectreCalendar" { InModuleScope "PwshSpectreConsole" { BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + $testBorder = 'Markdown' $testColor = Get-RandomColor Write-Debug $testBorder Write-Debug $testColor Mock Write-AnsiConsole { - param( - [Parameter(Mandatory)] - [Spectre.Console.Rendering.Renderable] $RenderableObject - ) - try { - $writer = [System.IO.StringWriter]::new() - $output = [Spectre.Console.AnsiConsoleOutput]::new($writer) - $settings = [Spectre.Console.AnsiConsoleSettings]::new() - $settings.Out = $output - $console = [Spectre.Console.AnsiConsole]::Create($settings) - $console.Write($RenderableObject) - $writer.ToString() - } - finally { - $writer.Dispose() - } + $testConsole.Write($RenderableObject) } } It "writes calendar for a date" { - $sample = Write-SpectreCalendar -Date "2024-01-01" -Culture "en-us" -Border $testBorder -Color $testColor + Write-SpectreCalendar -Date "2024-01-01" -Culture "en-us" -Border $testBorder -Color $testColor + $sample = $testConsole.Output $object = $sample -split '\r?\n' $object[0] | Should -Match 'January\s+2024' $rawdays = $object[2] @@ -50,14 +39,16 @@ Describe "Write-SpectreCalendar" { '2022-03-10' = 'Event 1' '2022-03-20' = 'Event 2' } - $sample = Write-SpectreCalendar -Date "2024-03-01" -Events $events -Culture "en-us" -Border Markdown -Color $testColor - $sample.count | Should -Be 2 - $sample[0] | Should -Match 'March\s+2024' - $sample[1] | Should -Match 'Event 1' + Write-SpectreCalendar -Date "2024-03-01" -Events $events -Culture "en-us" -Border Markdown -Color $testColor + $sample = $testConsole.Output + $sample | Should -Match 'March\s+2024' + $sample | Should -Match 'Event 1' Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 2 -Exactly } + It "writes calendar for a date with something else going on" { - $sample = Write-SpectreCalendar -Date 2024-07-01 -HideHeader -Border Markdown -Color $testColor + Write-SpectreCalendar -Date 2024-07-01 -HideHeader -Border Markdown -Color $testColor + $sample = $testConsole.Output $object = $sample -split '\r?\n' | Select-Object -Skip 1 -SkipLast 3 $object.count | Should -Be 7 [string[]]$results = 1..31 @@ -70,5 +61,28 @@ Describe "Write-SpectreCalendar" { } Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly } + + It "Should match the snapshot" { + Mock Write-AnsiConsole { + $testConsole.Write($RenderableObject) + } + $events = @{ + '2022-03-10' = 'Event 1' + '2022-03-20' = 'Event 2' + } + Write-SpectreCalendar -Date 2024-07-01 -Events $events -Border "Rounded" -Color "SpringGreen3" + $snapshotComparison = "$PSScriptRoot\..\@snapshots\Write-SpectreCalendar.snapshot.compare.txt" + Set-Content -Path $snapShotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapshotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Write-SpectreCalendar.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } + } } } diff --git a/PwshSpectreConsole.Tests/writing/Write-SpectreFigletText.tests.ps1 b/PwshSpectreConsole.Tests/writing/Write-SpectreFigletText.tests.ps1 index 367d14c6..547ffb1e 100644 --- a/PwshSpectreConsole.Tests/writing/Write-SpectreFigletText.tests.ps1 +++ b/PwshSpectreConsole.Tests/writing/Write-SpectreFigletText.tests.ps1 @@ -6,6 +6,8 @@ Describe "Write-SpectreFigletText" { InModuleScope "PwshSpectreConsole" { BeforeEach { $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + [Spectre.Console.Testing.TestConsoleExtensions]::Width($testConsole, 180) $testColor = Get-RandomColor $testAlignment = Get-RandomJustify Mock Write-AnsiConsole { @@ -26,5 +28,29 @@ Describe "Write-SpectreFigletText" { { Write-SpectreFigletText -FigletFontPath "notfound.flf" } | Should -Throw Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 0 -Exactly } + + It "Should match the snapshot" { + Mock Write-AnsiConsole { + $testConsole.Write($RenderableObject) + } + $testTitle = "f i glett" + $testAlignment = "Center" + $testColor = "DarkSeaGreen1_1" + + Write-SpectreFigletText -Text $testTitle -Alignment $testAlignment -Color $testColor + + $snapshotComparison = "$PSScriptRoot\..\@snapshots\Write-SpectreFigletText.snapshot.compare.txt" + Set-Content -Path $snapshotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapshotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Write-SpectreFigletText.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } + } } } \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/writing/Write-SpectreHost.tests.ps1 b/PwshSpectreConsole.Tests/writing/Write-SpectreHost.tests.ps1 index a5514f3f..d7af322d 100644 --- a/PwshSpectreConsole.Tests/writing/Write-SpectreHost.tests.ps1 +++ b/PwshSpectreConsole.Tests/writing/Write-SpectreHost.tests.ps1 @@ -5,37 +5,53 @@ Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force Describe "Write-SpectreHost" { InModuleScope "PwshSpectreConsole" { BeforeEach { + $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true $testMessage = Get-RandomString $testMessage | Out-Null - Mock Write-SpectreHostInternalMarkup - Mock Write-SpectreHostInternalMarkupLine + Mock Write-SpectreHostInternalMarkup { + $Message | Should -Be $testMessage + [AnsiConsoleExtensions]::Markup($testConsole, $Message) + } + Mock Write-SpectreHostInternalMarkupLine { + $Message | Should -Be $testMessage + [AnsiConsoleExtensions]::MarkupLine($testConsole, $Message) + } } It "writes a message" { - Mock Write-SpectreHostInternalMarkupLine -Verifiable -ParameterFilter { - $Message -eq $testMessage - } Write-SpectreHost -Message $testMessage Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkupLine" -Times 1 -Exactly - Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkup" -Times 0 -Exactly + $testConsole.Output.Split("`n").Count | Should -Be 2 } It "accepts pipeline input" { - Mock Write-SpectreHostInternalMarkupLine -Verifiable -ParameterFilter { - $Message -eq $testMessage - } $testMessage | Write-SpectreHost Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkupLine" -Times 1 -Exactly - Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkup" -Times 0 -Exactly + $testConsole.Output.Split("`n").Count | Should -Be 2 } It "handles nonewline" { - Mock Write-SpectreHostInternalMarkup -Verifiable -ParameterFilter { - $Message -eq $testMessage - } Write-SpectreHost -Message $testMessage -NoNewline Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkup" -Times 1 -Exactly - Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkupLine" -Times 0 -Exactly + $testConsole.Output.Split("`n").Count | Should -Be 1 + } + + It "Should match the snapshot" { + $testMessage = "[#00ff00]Hello[/], [DeepSkyBlue3_1]World![/] :smiling_face_with_sunglasses: Yay!" + Write-SpectreHost $testMessage + $snapshotComparison = "$PSScriptRoot\..\@snapshots\Write-SpectreHost.snapshot.compare.txt" + Set-Content -Path $snapShotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapshotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Write-SpectreHost.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } } } } \ No newline at end of file diff --git a/PwshSpectreConsole.Tests/writing/Write-SpectreRule.tests.ps1 b/PwshSpectreConsole.Tests/writing/Write-SpectreRule.tests.ps1 index a2040ca1..a69dc0a5 100644 --- a/PwshSpectreConsole.Tests/writing/Write-SpectreRule.tests.ps1 +++ b/PwshSpectreConsole.Tests/writing/Write-SpectreRule.tests.ps1 @@ -6,6 +6,8 @@ Describe "Write-SpectreRule" { InModuleScope "PwshSpectreConsole" { BeforeEach { $testConsole = [Spectre.Console.Testing.TestConsole]::new() + $testConsole.EmitAnsiSequences = $true + [Spectre.Console.Testing.TestConsoleExtensions]::Width($testConsole, 140) $testColor = Get-RandomColor Write-Debug $testColor $justification = Get-RandomJustify @@ -23,5 +25,29 @@ Describe "Write-SpectreRule" { Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly $testConsole.Output | Should -BeLike "*$randomString*" } + + It "Should match the snapshot" { + Mock Write-AnsiConsole { + $testConsole.Write($RenderableObject) + } + $testTitle = "yo, this is a test rule" + $justification = "Center" + $testColor = "Red" + + Write-SpectreRule -Title $testTitle -Alignment $justification -Color $testColor + + $snapshotComparison = "$PSScriptRoot\..\@snapshots\Write-SpectreRule.snapshot.compare.txt" + Set-Content -Path $snapshotComparison -Value ($testConsole.Output -replace "`r", "") -NoNewline + $compare = Get-Content -Path $snapshotComparison -AsByteStream + $snapshot = Get-Content -Path "$PSScriptRoot\..\@snapshots\Write-SpectreRule.snapshot.txt" -AsByteStream + try { + $snapshot | Should -Be $compare + } catch { + # byte array to string + Write-Host "Expected:`n`n$([System.Text.Encoding]::UTF8.GetString($snapshot))" + Write-Host "Got:`n`n$([System.Text.Encoding]::UTF8.GetString($compare))" + throw + } + } } } \ No newline at end of file diff --git a/PwshSpectreConsole/private/Convert-ToSpectreColor.ps1 b/PwshSpectreConsole/private/Convert-ToSpectreColor.ps1 index 86ec1492..6db1f626 100644 --- a/PwshSpectreConsole/private/Convert-ToSpectreColor.ps1 +++ b/PwshSpectreConsole/private/Convert-ToSpectreColor.ps1 @@ -1,4 +1,3 @@ -using module ".\completions\Completers.psm1" using namespace Spectre.Console <# @@ -26,7 +25,6 @@ The color to convert. This parameter is mandatory and accepts input from the pip function Convert-ToSpectreColor { param ( [Parameter(ValueFromPipeline, Mandatory)] - [ValidateSpectreColor()] [object] $Color ) try { diff --git a/PwshSpectreConsole/private/Write-SpectreHostInternal.ps1 b/PwshSpectreConsole/private/Write-SpectreHostInternal.ps1 index d8a2536f..442aa80a 100644 --- a/PwshSpectreConsole/private/Write-SpectreHostInternal.ps1 +++ b/PwshSpectreConsole/private/Write-SpectreHostInternal.ps1 @@ -6,7 +6,7 @@ function Write-SpectreHostInternalMarkup { [Parameter(Mandatory)] [string] $Message ) - [AnsiConsole]::Markup($Message) + [AnsiConsoleExtensions]::Markup([AnsiConsole]::Console, $Message) } function Write-SpectreHostInternalMarkupLine { @@ -14,5 +14,5 @@ function Write-SpectreHostInternalMarkupLine { [Parameter(Mandatory)] [string] $Message ) - [AnsiConsole]::MarkupLine($Message) + [AnsiConsoleExtensions]::MarkupLine([AnsiConsole]::Console, $Message) } \ No newline at end of file diff --git a/PwshSpectreConsole/public/demo/Start-SpectreDemo.ps1 b/PwshSpectreConsole/public/demo/Start-SpectreDemo.ps1 index 92cdc13d..8cfe484e 100644 --- a/PwshSpectreConsole/public/demo/Start-SpectreDemo.ps1 +++ b/PwshSpectreConsole/public/demo/Start-SpectreDemo.ps1 @@ -322,7 +322,7 @@ Invoke-SpectreCommandWithProgress -ScriptBlock { $example = @" Get-SpectreImageExperimental "$PSScriptRoot\..\..\private\images\harveyspecter.gif" -LoopCount 2 -Write-SpectreHost "I'm Harvey Specter. Are you after a Specter consult or a .?" +Write-SpectreHost "I'm Harvey Specter. Are you after a Specter consult or a Spectre.Console?" "@ $example | Write-SpectreExample -Title "View Images" -Description "Images can be rendered in the terminal, given a path to an image Spectre Console will downsample the image to a resolution that will fit within the terminal width or you can choose your own width setting." Invoke-Expression $example diff --git a/PwshSpectreConsole/public/formatting/New-SpectreChartItem.ps1 b/PwshSpectreConsole/public/formatting/New-SpectreChartItem.ps1 index fe907d7b..23c46beb 100644 --- a/PwshSpectreConsole/public/formatting/New-SpectreChartItem.ps1 +++ b/PwshSpectreConsole/public/formatting/New-SpectreChartItem.ps1 @@ -37,5 +37,5 @@ function New-SpectreChartItem { [Color]$Color ) - return [SpectreChartItem]::new($Label, $Value, $Color.ToMarkup()) + return [SpectreChartItem]::new($Label, $Value, $Color) } diff --git a/PwshSpectreConsole/public/writing/Write-SpectreHost.ps1 b/PwshSpectreConsole/public/writing/Write-SpectreHost.ps1 index c5ea9acd..8cd03ab2 100644 --- a/PwshSpectreConsole/public/writing/Write-SpectreHost.ps1 +++ b/PwshSpectreConsole/public/writing/Write-SpectreHost.ps1 @@ -27,8 +27,8 @@ function Write-SpectreHost { ) if($NoNewline) { - Write-SpectreHostInternalMarkup -Message $Message + Write-SpectreHostInternalMarkup $Message } else { - Write-SpectreHostInternalMarkupLine -Message $Message + Write-SpectreHostInternalMarkupLine $Message } } \ No newline at end of file