Skip to content

Format-SpectreTree

Description

This function takes a hashtable and formats it as a tree using Spectre Console. The hashtable should have a ‘Value’ key and a ‘Children’ key. The ‘Value’ key should contain the Spectre Console renderable item (text or other objects like calendars etc.) for the node of the tree, and the ‘Children’ key should contain an array of hashtables representing the child nodes of the node.
See https://spectreconsole.net/widgets/tree for more information.


Examples

Example 1
This example demonstrates how to display a tree with multiple children.

Terminal window
$calendar = Write-SpectreCalendar -Date 2024-07-01 -PassThru
$data = @{
Value = "Root"
Children = @(
@{
Value = "Child 1"
Children = @(
@{
Value = "Grandchild 1"
Children = @()
},
@{
Value = $calendar
Children = @()
}
)
},
@{
Value = "Child 2"
Children = @()
}
)
}
Format-SpectreTree -Data $data -Guide BoldLine -Color "Green"

Parameters

Data

The hashtable to format as a tree.

TypeRequiredPositionPipelineInput
[Hashtable]true1true (ByValue)

Guide

The type of line to use for the tree.

Valid Values:

  • Ascii
  • BoldLine
  • DoubleLine
  • Line
TypeRequiredPositionPipelineInputAliases
[String]false2falseBorder

Color

The color to use for the tree. This can be a Spectre Console color name or a hex color code. Default is the accent color defined in the script.

TypeRequiredPositionPipelineInput
[Color]false3false

Syntax

Terminal window
Format-SpectreTree [-Data] <Hashtable> [[-Guide] <String>] [[-Color] <Color>] [<CommonParameters>]