Skip to content
ConsoleMonster
Class

Tree

ConsoleMonster.Widgets

Namespace
ConsoleMonster.Widgets
Assembly
ConsoleMonster
Implements
IWidget
Modifiers
sealed

A hierarchy with guide lines (├──, └──, │ on Full/Basic; |-- on Ascii). Guides use the border colour so the labels carry the attention. Long labels are truncated with an ellipsis.

Inheritance

  • object
  • Tree

Usage

Explore 62 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 31

Constructors

public Tree(string? title = null) #

Creates a tree.

Parameters

title string? = null optional
The root label (markup), or null to show only the children as top-level nodes.

Methods

Add 2 overloads
public TreeNode Add(string label, StatusKind? status = null, string? detail = null) #

Adds a top-level node.

Parameters

label string required
The label (markup).
status ConsoleMonster.Styling.StatusKind? = null optional
An optional status.
detail string? = null optional
An optional muted detail.

Returns

TreeNode The new node.
public TreeNode Add(RichText label, StatusKind? status = null, string? detail = null) #

Adds a top-level node with a multicolour label.

Parameters

label ConsoleMonster.Text.RichText required
The label.
status ConsoleMonster.Styling.StatusKind? = null optional
An optional status.
detail string? = null optional
An optional muted detail.

Returns

TreeNode The new node.
public Size Measure(Constraints constraints, RenderContext context) #

Returns the size the widget wants within the constraints.

Parameters

constraints ConsoleMonster.Layout.Constraints required
The space offered.
context ConsoleMonster.Canvas.RenderContext required
Profile, theme and glyphs.

Returns

Size The desired size, never larger than the constraints.
public void Render(Region region, RenderContext context) #

Renders into a region. The region may be smaller or larger than the measured size.

Parameters

region ConsoleMonster.Canvas.Region required
The target region.
context ConsoleMonster.Canvas.RenderContext required
Profile, theme and glyphs.

Properties

public IList<TableColumn> ValueColumns { get; } #

Aligned value columns, keyed by TableColumn.Id in TreeNode.Values. Default alignment is right. Wide layouts reserve at least 40% for labels and shrink value columns before dropping them. Below 120 cells fitting detail precedes value notes. Lower priorities drop first; labels always receive space first. With columns the tree uses single-line labels, regardless of Tree.WrapLabels.

public bool ShowValueHeaders { get; set; } #

Show headings above aligned value columns (default true).

public string? Title { get; set; } #

The root title (markup); null hides the root while preserving its children.

public TreeNode Root { get; } #

The root node.

public bool ShowRoot { get; set; } #

Whether the root label is shown.

public bool CompactGuides { get; set; } #

Use three-cell guides rather than the original four-cell guides.

public TreeValuePlacement ValuePlacement { get; set; } #

Where value columns begin. Default views use AfterLabel.

public bool WrapLabels { get; set; } #

Wrap labels, values and notes with a hanging indent instead of shortening them (default false).

public bool TruncateLabelsInMiddle { get; set; } #

Use a middle ellipsis for shortened identity labels, preserving both ends (default false).

public bool TruncateNotesInMiddle { get; set; } #

Use the rendering context's middle ellipsis for shortened notes and value notes, preserving both ends (default false). Labels keep priority; wrapped notes continue to wrap.

public bool DetectRepeatedNodes { get; set; } #

Mark identities seen on earlier branches as shown above instead of expanding them again.

public Func<TreeNode, string>? CollapsedSummary { get; set; } #
Fluent("CollapsedSummaryBy")

Produces a plain text aggregate for explicitly collapsed nodes; never enumerates descendants itself.

public PresentationOptions Presentation { get; set; } #

Culture, clock and time zone for node values.

Extension Methods

public static Tree CollapsedSummaryBy(Tree tree, Func<TreeNode, string>? value) #

Sets Tree.CollapsedSummary: Produces a plain text aggregate for explicitly collapsed nodes; never enumerates descendants itself.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value System.Func<ConsoleMonster.Widgets.TreeNode, string>? required
The callback.

Returns

Tree The same instance.

Examples

// C# initializer or property                                            // C# fluent
new global::ConsoleMonster.Widgets.Tree { CollapsedSummary = value };    Ui.Tree().CollapsedSummaryBy(value);
public static Tree CompactGuides(Tree tree, bool value = true) #

Sets Tree.CompactGuides: Use three-cell guides rather than the original four-cell guides.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Tree The same instance.

Examples

// C# initializer or property                                         // C# fluent
new global::ConsoleMonster.Widgets.Tree { CompactGuides = value };    Ui.Tree().CompactGuides(value);
public static Tree DetectRepeatedNodes(Tree tree, bool value = true) #

Sets Tree.DetectRepeatedNodes: Mark identities seen on earlier branches as shown above instead of expanding them again.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Tree The same instance.

Examples

// C# initializer or property                                               // C# fluent
new global::ConsoleMonster.Widgets.Tree { DetectRepeatedNodes = value };    Ui.Tree().DetectRepeatedNodes(value);
Presentation 2 overloads
public static Tree Presentation(Tree tree, PresentationOptions value) #

Sets Tree.Presentation: Culture, clock and time zone for node values.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value ConsoleMonster.Presenters.PresentationOptions required
The value.

Returns

Tree The same instance.

Examples

// C# initializer or property                                        // C# fluent
new global::ConsoleMonster.Widgets.Tree { Presentation = value };    Ui.Tree().Presentation(value);
public static Tree Presentation(Tree tree, Action<PresentationOptions> configure) #

Configures Tree.Presentation in place (creating it when not set): Culture, clock and time zone for node values.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
configure System.Action<ConsoleMonster.Presenters.PresentationOptions> required
Configures the value.

Returns

Tree The same instance.
public static Tree Root(Tree tree, Action<TreeNode> configure) #

Configures Tree.Root in place: The root node.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
configure System.Action<ConsoleMonster.Widgets.TreeNode> required
Configures the value.

Returns

Tree The same instance.
public static Tree ShowRoot(Tree tree, bool value = true) #

Sets Tree.ShowRoot: Whether the root label is shown.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Tree The same instance.

Examples

// C# initializer or property                                    // C# fluent
new global::ConsoleMonster.Widgets.Tree { ShowRoot = value };    Ui.Tree().ShowRoot(value);
public static Tree ShowValueHeaders(Tree tree, bool value = true) #

Sets Tree.ShowValueHeaders: Show headings above aligned value columns (default true).

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Tree The same instance.

Examples

// C# initializer or property                                            // C# fluent
new global::ConsoleMonster.Widgets.Tree { ShowValueHeaders = value };    Ui.Tree().ShowValueHeaders(value);
public static Tree Title(Tree tree, string? value) #

Sets Tree.Title: The root title (markup); null hides the root while preserving its children.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value string? required
The value.

Returns

Tree The same instance.

Examples

// C# initializer or property                                 // C# fluent
new global::ConsoleMonster.Widgets.Tree { Title = value };    Ui.Tree().Title(value);
public static Tree TruncateLabelsInMiddle(Tree tree, bool value = true) #

Sets Tree.TruncateLabelsInMiddle: Use a middle ellipsis for shortened identity labels, preserving both ends (default false).

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Tree The same instance.

Examples

// C# initializer or property                                                  // C# fluent
new global::ConsoleMonster.Widgets.Tree { TruncateLabelsInMiddle = value };    Ui.Tree().TruncateLabelsInMiddle(value);
public static Tree TruncateNotesInMiddle(Tree tree, bool value = true) #

Sets Tree.TruncateNotesInMiddle: Use the rendering context's middle ellipsis for shortened notes and value notes, preserving both ends (default false). Labels keep priority; wrapped notes continue to wrap.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Tree The same instance.

Examples

// C# initializer or property                                                 // C# fluent
new global::ConsoleMonster.Widgets.Tree { TruncateNotesInMiddle = value };    Ui.Tree().TruncateNotesInMiddle(value);
public static Tree ValueColumn(Tree tree, TableColumn item) #

Adds an item to Tree.ValueColumns: Aligned value columns, keyed by TableColumn.Id in TreeNode.Values. Default alignment is right. Wide layouts reserve at least 40% for labels and shrink value columns before dropping them. Below 120 cells fitting detail precedes value notes. Lower priorities drop first; labels always receive space first. With columns the tree uses single-line labels, regardless of Tree.WrapLabels.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
item ConsoleMonster.Widgets.TableColumn required
The item.

Returns

Tree The same instance.
public static Tree ValueColumns(Tree tree, IEnumerable<TableColumn> items) #

Adds items to Tree.ValueColumns: Aligned value columns, keyed by TableColumn.Id in TreeNode.Values. Default alignment is right. Wide layouts reserve at least 40% for labels and shrink value columns before dropping them. Below 120 cells fitting detail precedes value notes. Lower priorities drop first; labels always receive space first. With columns the tree uses single-line labels, regardless of Tree.WrapLabels.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
items System.Collections.Generic.IEnumerable<ConsoleMonster.Widgets.TableColumn> required
The items, in order.

Returns

Tree The same instance.
public static Tree ValuePlacement(Tree tree, TreeValuePlacement value) #

Sets Tree.ValuePlacement: Where value columns begin. Default views use AfterLabel.

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value ConsoleMonster.Widgets.TreeValuePlacement required
The value.

Returns

Tree The same instance.

Examples

// C# initializer or property                                          // C# fluent
new global::ConsoleMonster.Widgets.Tree { ValuePlacement = value };    Ui.Tree().ValuePlacement(value);
public static Tree WrapLabels(Tree tree, bool value = true) #

Sets Tree.WrapLabels: Wrap labels, values and notes with a hanging indent instead of shortening them (default false).

Parameters

tree ConsoleMonster.Widgets.Tree required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Tree The same instance.

Examples

// C# initializer or property                                      // C# fluent
new global::ConsoleMonster.Widgets.Tree { WrapLabels = value };    Ui.Tree().WrapLabels(value);