Skip to content

Format-SpectreGrid

Description

Formats data into a Spectre Console grid. The grid can be used to display data in a tabular format but it’s not as flexible as the Layout widget.
See https://spectreconsole.net/widgets/grid for more information.


Examples

Example 1
This example demonstrates how to display a grid of rows using the Spectre Console module with a list of lists.

Terminal window
Format-SpectreGrid -Data @("hello", "I", "am"), @("a", "grid", "of"), @("rows", "using", "spectre")

Example 2
This example demonstrates how to display a grid of rows using the Spectre Console module with a list of New-SpectreGridRow objects. The New-SpectreGridRow function is used to create the rows when you want to avoid array collapsing in PowerShell turning your rows into a single array of columns.

Terminal window
$rows = 4
$cols = 6
$gridRows = @()
for ($row = 1; $row -le $rows; $row++) {
$columns = @()
for ($col = 1; $col -le $cols; $col++) {
$columns += "Row $row, Col $col" | Format-SpectrePanel
}
$gridRows += New-SpectreGridRow $columns
}
$gridRows | Format-SpectreGrid

Parameters

Data

The data to be displayed in the grid. This can be a list of lists or a list of New-SpectreGridRow objects.

TypeRequiredPositionPipelineInput
[Object]true1true (ByValue)

Width

The width of the grid. If not specified, the grid width will be automatic.

TypeRequiredPositionPipelineInput
[Int32]false2false

Padding

The padding to apply to the grid items. The default is 1.

TypeRequiredPositionPipelineInput
[Int32]false3false

Syntax

Terminal window
Format-SpectreGrid [-Data] <Object> [[-Width] <Int32>] [[-Padding] <Int32>] [<CommonParameters>]