-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Yeet in a bunch of additional spectre console functionality
- Loading branch information
1 parent
dca82c1
commit 31a3ffa
Showing
15 changed files
with
319 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function ConvertTo-Renderable { | ||
param ( | ||
[object] $InputData | ||
) | ||
|
||
# These objects are already renderable | ||
if ($InputData -is [Spectre.Console.Rendering.Renderable]) { | ||
return $InputData | ||
} | ||
|
||
$renderableItems = @() | ||
|
||
if ($InputData -is [array]) { | ||
foreach ($column in $InputData) { | ||
$renderableItems += ConvertTo-Renderable $column | ||
} | ||
} else { | ||
# For others just dump them as either strings formatted with markup which are easy to identify by the closing tag [/] or as plain text | ||
if ($InputData -like "*[/]*") { | ||
$renderableItems += [Spectre.Console.Markup]::new($InputData) | ||
} else { | ||
$renderableItems += [Spectre.Console.Text]::new(($InputData | Out-String -NoNewline)) | ||
} | ||
} | ||
|
||
return $renderableItems | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class SpectreGridRow { | ||
|
||
hidden [Spectre.Console.Rendering.Renderable[]] $InternalColumns = @() | ||
|
||
[int] Count() { | ||
return $this.InternalColumns.Count | ||
} | ||
|
||
[Spectre.Console.GridRow] ToGridRow() { | ||
return [Spectre.Console.GridRow]::new([Spectre.Console.Rendering.Renderable[]]$this.InternalColumns) | ||
} | ||
|
||
SpectreGridRow([object[]] $Columns) { | ||
foreach ($column in $Columns) { | ||
if ($column -is [Spectre.Console.Rendering.Renderable]) { | ||
$this.InternalColumns += $column | ||
} elseif ($column -like "*[/]*") { | ||
$this.InternalColumns += [Spectre.Console.Markup]::new($column) | ||
} else { | ||
$this.InternalColumns += [Spectre.Console.Text]::new($column.ToString().TrimEnd()) | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
PwshSpectreConsole/public/formatting/Format-SpectreAligned.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using module "..\..\private\completions\Completers.psm1" | ||
using module "..\..\private\completions\Transformers.psm1" | ||
|
||
function Format-SpectreAligned { | ||
<# | ||
.SYNOPSIS | ||
Wraps a renderable object in a Spectre Console Aligned object. | ||
.DESCRIPTION | ||
TODO Description | ||
#> | ||
[Reflection.AssemblyMetadata("title", "Format-SpectreAligned")] | ||
param( | ||
[Parameter(ValueFromPipeline, Mandatory)] | ||
[RenderableTransformationAttribute()] | ||
[object] $Data, | ||
[ValidateSet([SpectreConsoleHorizontalAlignment], ErrorMessage = "Value '{0}' is invalid. Try one of: {1}")] | ||
[string] $HorizontalAlignment = "Center", | ||
[ValidateSet([SpectreConsoleVerticalAlignment], ErrorMessage = "Value '{0}' is invalid. Try one of: {1}")] | ||
[string] $VerticalAlignment = "Middle" | ||
) | ||
|
||
$aligned = [Spectre.Console.Align]::new( | ||
$Data, | ||
[Spectre.Console.HorizontalAlignment]::$HorizontalAlignment, | ||
[Spectre.Console.VerticalAlignment]::$VerticalAlignment | ||
) | ||
|
||
return $aligned | ||
} |
58 changes: 58 additions & 0 deletions
58
PwshSpectreConsole/public/formatting/Format-SpectreGrid.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using module "..\..\private\completions\Completers.psm1" | ||
using module "..\..\private\completions\Transformers.psm1" | ||
|
||
function Format-SpectreGrid { | ||
<# | ||
.SYNOPSIS | ||
TODO - Add synopsis | ||
.DESCRIPTION | ||
TODO - Add description | ||
#> | ||
[Reflection.AssemblyMetadata("title", "Format-SpectreGrid")] | ||
# two parameter sets, one for padding evenly and one for specifing tlbr separately | ||
param ( | ||
[Parameter(ValueFromPipeline, Mandatory)] | ||
[GridRowTransformationAttribute()] | ||
[object]$Data, | ||
[ValidateSet([SpectreConsoleJustify], ErrorMessage = "Value '{0}' is invalid. Try one of: {1}")] | ||
[string] $Justify = 'Left', | ||
[int] $Width | ||
) | ||
|
||
begin { | ||
$grid = [Spectre.Console.Grid]::new() | ||
$columnsSet = $false | ||
if ($Width) { | ||
$grid.Width = $Width | ||
} | ||
$grid.Alignment = [Spectre.Console.Justify]::$Justify | ||
$grid = $grid.AddColumn() | ||
} | ||
|
||
process { | ||
if ($Data -is [array]) { | ||
foreach ($row in $Data) { | ||
if (!$columnsSet) { | ||
0..($row.Count() - 1) | ForEach-Object { | ||
$grid = $grid.AddColumn() | ||
} | ||
$columnsSet = $true | ||
} | ||
$grid = $grid.AddRow($row.ToGridRow()) | ||
} | ||
} else { | ||
if (!$columnsSet) { | ||
0..($row.Count() - 1) | ForEach-Object { | ||
$grid = $grid.AddColumn() | ||
} | ||
$columnsSet = $true | ||
} | ||
$grid = $grid.AddRow($Data.ToGridRow()) | ||
} | ||
} | ||
|
||
end { | ||
return $grid | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
PwshSpectreConsole/public/formatting/Format-SpectrePadded.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using module "..\..\private\completions\Transformers.psm1" | ||
|
||
function Format-SpectrePadded { | ||
<# | ||
.SYNOPSIS | ||
Renders a collection of renderables in rows to the console. | ||
.DESCRIPTION | ||
This function creates a spectre rows widget that renders a collection of renderables in autosized rows to the console. | ||
Rows can contain renderable items, see https://spectreconsole.net/widgets/rows for more information. | ||
.PARAMETER Data | ||
An array of objects containing the data to be displayed in the rows. | ||
#> | ||
[Reflection.AssemblyMetadata("title", "Format-SpectrePadded")] | ||
# two parameter sets, one for padding evenly and one for specifing tlbr separately | ||
param ( | ||
[Parameter(ValueFromPipeline, Mandatory)] | ||
[RenderableTransformationAttribute()] | ||
[object] $Data, | ||
[Parameter(ParameterSetName = 'Global', Mandatory)] | ||
[int] $Padding, | ||
[Parameter(ParameterSetName = 'Specific', Mandatory)] | ||
[int] $Top, | ||
[Parameter(ParameterSetName = 'Specific', Mandatory)] | ||
[int] $Left, | ||
[Parameter(ParameterSetName = 'Specific', Mandatory)] | ||
[int] $Bottom, | ||
[Parameter(ParameterSetName = 'Specific', Mandatory)] | ||
[int] $Right, | ||
[Parameter(ParameterSetName = 'Expand', Mandatory)] | ||
[switch] $Expand | ||
) | ||
|
||
$paddedRenderable = [Spectre.Console.Padder]::new($Data) | ||
|
||
if ($PSCmdlet.ParameterSetName -eq 'Expand') { | ||
$paddedRenderable.Expand = $true | ||
} elseif ($PSCmdlet.ParameterSetName -eq 'Global') { | ||
$paddedRenderable.Padding = [Spectre.Console.Padding]::new($Padding) | ||
} elseif ($PSCmdlet.ParameterSetName -eq 'Specific') { | ||
$paddedRenderable.Padding = [Spectre.Console.Padding]::new($Left, $Top, $Right, $Bottom) | ||
} | ||
|
||
return $paddedRenderable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
PwshSpectreConsole/public/formatting/New-SpectreGridRow.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<# | ||
.SYNOPSIS | ||
TODO - Add synopsis | ||
.DESCRIPTION | ||
TODO - Add description | ||
#> | ||
function New-SpectreGridRow { | ||
[Reflection.AssemblyMetadata("title", "New-SpectreGridRow")] | ||
param ( | ||
[Parameter(Mandatory)] | ||
[array]$Data | ||
) | ||
|
||
$renderableColumns = @() | ||
foreach ($column in $Data) { | ||
$renderableColumns += ConvertTo-Renderable $column | ||
} | ||
|
||
$gridRow = [SpectreGridRow]::new($renderableColumns) | ||
|
||
return $gridRow | ||
} |
Oops, something went wrong.