Tree
ITree renders hierarchical data with branch-drawing glyphs. Each node can have any number of children; branches use fork / last / continue guides.
![]()
When to use
- Project trees, file systems, package dependencies.
- Anywhere you want indented hierarchy with visual connectors.
For interactive picks from a hierarchy, see Hierarchical selection.
Basic usage
pascal
var
t : ITree;
src : ITreeNode;
begin
t := Widgets.Tree('[bold]Project[/]');
src := t.AddNode('source');
src.AddNode('VSoft.AnsiConsole.Color.pas');
src.AddNode('VSoft.AnsiConsole.Style.pas');
t.AddNode('tests');
AnsiConsole.Write(t);
end;1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Renders:
Project
├── source
│ ├── VSoft.AnsiConsole.Color.pas
│ └── VSoft.AnsiConsole.Style.pas
└── tests1
2
3
4
5
2
3
4
5
Building the tree
The root accepts either a markup string or any renderable:
pascal
t := Widgets.Tree('[bold yellow]src[/]');
t := Widgets.Tree(Widgets.Panel(Widgets.Text('root')));1
2
2
Each AddNode call returns the new ITreeNode, so you can drill in:
pascal
core := t.AddNode('Core');
core.AddNode('Color');
core.AddNode('Style');
widgets := t.AddNode('Widgets');
table := widgets.AddNode('Table');
table.AddNode('Borders');1
2
3
4
5
6
7
2
3
4
5
6
7
Configuration
| Method | Purpose |
|---|---|
WithGuide(kind) | Glyph set — TTreeGuideKind.Ascii / Line (default) / Heavy / Double / Bold. |
WithStyle(value) | Style applied to the guide glyphs. |
WithExpanded(value) | When False, render only the root and immediate children. |
pascal
AnsiConsole.Write(
Widgets.Tree('[bold]Project[/]')
.WithGuide(TTreeGuideKind.Heavy)
.WithStyle(TAnsiStyle.Plain.WithForeground(TAnsiColor.Aqua)));1
2
3
4
2
3
4
Composition
Markup tags inside node labels:
pascal
t.AddNode('[red]TODO: cross-platform[/]');
t.AddNode('[green]build ok[/]');
t.AddNode('[yellow]tests pending[/]');1
2
3
2
3
Nodes can hold any renderable:
pascal
node := t.AddNode(Widgets.Panel(Widgets.Markup('inline panel')));1
API reference
Widgets.Tree(root : IRenderable)Widgets.Tree(rootMarkup : string)ITree— interface.- Demo:
demos/snippets/Tree.
See also
- Tree guides reference — every
TTreeGuideKindglyph. - Hierarchical selection — interactive tree picker.
- Panel — wrapping a tree in a bordered region.