Skip to content
ConsoleMonster
Cmdlet

New-ConsoleRegion

Module
ConsoleMonster
Inputs
System.Object
Outputs
ConsoleMonster.Layout.IWidget

Creates a named region whose content can be replaced while a dashboard runs.

Syntax

New-ConsoleRegion
[[-Content] <Object>]
[-Fill]
[-Height <Int32>]
[-Horizontal <Left|Center|Right>]
[-Padding <Int32[]>]
[-Vertical <Top|Middle|Bottom>]
[-Weight <Double>]
[[-WidgetId] <String>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Put the region anywhere in a layout (inside New-ConsolePanel keeps the frame), then call Update-Console -WidgetId with a new widget from the dashboard script. The swap is queued like every update, lands between frames and redraws only what changed.

Examples

Example 1

$panelOptions = @{
    Title = 'Result'
    Content = {
        $regionOptions = @{
            WidgetId = 'main'
            Content = {
                $progressOptions = @{
                    Indeterminate = $true
                    Label = 'Querying'
                    WidgetId = 'spinner'
                }
                New-ConsoleProgress @progressOptions
            }
        }
        New-ConsoleRegion @regionOptions
    }
}
New-ConsolePanel @panelOptions

Build a panel with an indeterminate spinner as its initial content. WidgetId main identifies the region for a later Update-Console -Content call. WidgetId spinner identifies the progress widget currently inside it.

Example 2

$regionOptions = @{
    Horizontal = 'Center'
    Padding = @(1)
    Content = {
        $textOptions = @{
            Text = @('Ready')
        }
        New-ConsoleText @textOptions
    }
}
New-ConsoleRegion @regionOptions | Show-Console

Center Ready and leave one cell of padding on each side. Padding is an integer array. The one-entry form uses that entry for all four sides. With two entries the order is horizontal then vertical. With four entries it is left, top, right, bottom.

Example 3

Get-ConsoleDemo -Slug 'build-steps' | Select-Object -ExpandProperty Source
Get-ConsoleDemo -Slug 'log-tail' | Select-Object -ExpandProperty Source

Read any of these gallery scripts to see New-ConsoleRegion in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.

Parameters

-Content Object optionalposition: 1pipeline: True (ByValue)
A script block whose widgets are the first content.
-Fill SwitchParameter optional
Takes the remaining height.
-Height Int32 optional
A fixed height in rows.
-Horizontal HorizontalAlignment optional
Horizontal placement within the available space.
Possible values: Left, Center, Right
-Padding Int32[] optional
Padding as one value for all sides, two for horizontal and vertical, or four for left, top, right and bottom.
-Vertical VerticalAlignment optional
Vertical placement within the available space.
Possible values: Top, Middle, Bottom
-Weight Double optional
The share of the remaining space in a row or column layout.
-WidgetId String optionalposition: 0
The region name used by Update-Console.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.