Skip to content

Commit

Permalink
Make demo more flexible on size
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLawrie committed Aug 31, 2024
1 parent a1d3250 commit 2bca433
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion PwshSpectreConsole/PwshSpectreConsole.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ FunctionsToExport = 'Add-SpectreJob', 'Format-SpectreBarChart',
'Format-SpectreRows', 'Format-SpectrePadded', 'Format-SpectreGrid',
'New-SpectreGridRow', 'Format-SpectreTextPath', 'New-SpectreLayout',
'Format-SpectreAligned', 'Out-SpectreHost', 'Add-SpectreTableRow',
'Invoke-SpectreLive', 'Format-SpectreException', 'Write-SpectreFeatures'
'Invoke-SpectreLive', 'Format-SpectreException', 'Get-SpectreDemoFeatures'

# 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 = @()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
function Write-SpectreFeatures {
<#
.SYNOPSIS
Demonstrates the features of Spectre.Console.
Write-SpectreHost "[underline][yellow]Spectre.Console[/][silver] Features[/][/]" -PassThru | Format-SpectreAligned -VerticalAlignment Middle
Write-SpectreHost " "
Write-SpectreHost " "
.DESCRIPTION
This script demonstrates the features of Spectre.Console. It shows off the various colors, styles, and other features that Spectre.Console supports.
.EXAMPLE
Get-SpectreDemoFeatures
#>
function Get-SpectreDemoFeatures {

$demoWidth = $Host.UI.RawUI.BufferSize.Width

$table = @{ Feature = "Feature"; Demo = "Demo" } | Format-SpectreTable -Border None
$title = Write-SpectreHost "[underline][yellow]Spectre.Console[/][silver] Features[/][/]" -PassThru | Format-SpectreAligned -VerticalAlignment Middle
$titleTable = Format-SpectreTable -Data @{
Title = $title
} -HideHeaders -Border None -Width $demoWidth

$titleTable | Format-SpectrePadded -Top 1 -Left 0 -Bottom 0 -Right 0 | Out-SpectreHost

# Colors
$colors = @()
Expand All @@ -19,7 +32,7 @@ function Write-SpectreFeatures {
# Spectrum
$spectrumRows = @()
$brightnesses = 12
$hues = 50
$hues = $demoWidth - 52
for ($b = 1; $b -le $brightnesses; $b+=2) {
$line = ""
for ($h = 0; $h -lt $hues; $h++) {
Expand All @@ -41,7 +54,7 @@ function Write-SpectreFeatures {
$table = Format-SpectreTable -Data @{
Feature = (Write-SpectreHost "[red]Colors[/] " -PassThru) # Force column width to be wide enough for the longest line
Demo = $colorColumns
} -Expand -HideHeaders -Border None
} -HideHeaders -Border None -Width $demoWidth
$table = Add-SpectreTableRow -Table $table -Columns @("", "")

# OS
Expand All @@ -63,7 +76,7 @@ function Write-SpectreFeatures {
(Write-SpectreHost "[green]$textToWrap[/]" -PassThru | Format-SpectreAligned -HorizontalAlignment Left),
(Write-SpectreHost "[yellow]$textToWrap[/]" -PassThru | Format-SpectreAligned -HorizontalAlignment Center),
(Write-SpectreHost "[blue]$textToWrap[/]" -PassThru | Format-SpectreAligned -HorizontalAlignment Right)
) | Format-SpectreGrid -Width 92
) | Format-SpectreGrid -Width $demoWidth
$wrapRows = $wrapRows | Format-SpectreRows
$table = Add-SpectreTableRow -Table $table -Columns @((Write-SpectreHost "[red]Wrap[/]" -PassThru), $wrapRows)
$table = Add-SpectreTableRow -Table $table -Columns @("", "")
Expand Down Expand Up @@ -125,21 +138,21 @@ function Write-SpectreFeatures {
Foo = "Qux"
Bar = "Corgi"
}
) | Format-SpectreTable -Color Yellow -Width 90
) | Format-SpectreTable -Color Yellow -Width ($demoWidth - 22)
$table = Add-SpectreTableRow -Table $table -Columns @((Write-SpectreHost "[red]Tables and Trees[/]" -PassThru), $embeddedTable)

# Charts
$breakdownChart = @(
(New-SpectreChartItem -Label "C#" -Value 82 -Color Green),
(New-SpectreChartItem -Label "PowerShell" -Value 13 -Color Red),
(New-SpectreChartItem -Label "Bash" -Value 5 -Color Blue)
) | Format-SpectreBreakdownChart -ShowPercentage -Width 41 | Format-SpectrePanel -Border Square -Color Grey -Height 5
) | Format-SpectreBreakdownChart -ShowPercentage -Width ([int](($demoWidth - 30) / 2)) | Format-SpectrePanel -Border Square -Color Grey -Height 5

$barChart = @(
(New-SpectreChartItem -Label "Apple" -Value 32 -Color Green),
(New-SpectreChartItem -Label "Oranges" -Value 13 -Color Orange1),
(New-SpectreChartItem -Label "Bananas" -Value 22 -Color Yellow)
) | Format-SpectreBarChart -Width 41 | Format-SpectrePanel -Border Square -Color Grey
) | Format-SpectreBarChart -Width ([int](($demoWidth - 30) / 2) - 1) | Format-SpectrePanel -Border Square -Color Grey

$chartColumns = Format-SpectreColumns -Data @(
$breakdownChart,
Expand Down Expand Up @@ -167,5 +180,7 @@ function Write-SpectreFeatures {
$table = Add-SpectreTableRow -Table $table -Columns @((Write-SpectreHost "[red]+ Much More![/]" -PassThru), $more)
$table = Add-SpectreTableRow -Table $table -Columns @("", "")

$table
$table | Format-SpectrePadded -Top 1 -Left 0 -Bottom 0 -Right 0 | Out-SpectreHost

Write-SpectreHost " "
}
4 changes: 1 addition & 3 deletions PwshSpectreConsole/public/formatting/Format-SpectreTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ function Format-SpectreTable {
[int] $Width,
[switch] $HideHeaders,
[String] $Title,
[switch] $AllowMarkup,
[switch] $Expand
[switch] $AllowMarkup
)
begin {
Write-Debug "Module: $($ExecutionContext.SessionState.Module.Name) Command: $($MyInvocation.MyCommand.Name) Param: $($PSBoundParameters.GetEnumerator())"
Expand All @@ -145,7 +144,6 @@ function Format-SpectreTable {
'Wrap' { $tableoptions.Wrap = $true ; $FormatTableParams.Wrap = $true }
'View' { $FormatTableParams.View = $View }
'Property' { $FormatTableParams.Property = $Property }
'Expand' { $table.Expand = $true }
}
}
process {
Expand Down

0 comments on commit 2bca433

Please sign in to comment.