PromptPlus

PromptPlus

PromptPlus

PromptPlusLibrary

ITreeSelectControl<T> Interface

Provides a fluent API for configuring and running the TreeSelect control, which browses an arbitrary hierarchy of items of type T as an expandable/collapsible tree.

public interface ITreeSelectControl<T>

Type parameters

T

The type of items in the tree.

Remarks

The tree structure is built explicitly by the caller through Root(T, bool), AddLast(T, bool)/AddFirst(T, bool) (first-level nodes), AddAfter(ITreeNode<T>, T, bool)/AddBefore(ITreeNode<T>, T, bool) (sibling insertion) and AddLast(T, bool)/ AddFirst(T, bool) (nested children). Whether a node is a container or a leaf is inferred from whether it has children. The rendered tree materializes visible rows lazily on expand and releases them on collapse, keeping memory proportional to what is visible. Nodes can be marked disable at creation time so they are shown and navigable but cannot be confirmed.

Methods

ITreeSelectControl<T>.AddAfter(ITreeNode<T>, T, bool) Method

Inserts a sibling immediately after node.

PromptPlusLibrary.ITreeNode<T> AddAfter(PromptPlusLibrary.ITreeNode<T> node, T value, bool disable=false);

Parameters

node PromptPlusLibrary.ITreeNode<T>

The reference sibling. Cannot be null.

value T

The value of the new node. Cannot be null.

disable System.Boolean

When true, the new node cannot be confirmed. Default is false.

Returns

PromptPlusLibrary.ITreeNode<T>

Exceptions

System.ArgumentNullException
When node is null.

System.InvalidOperationException
When node does not belong to this tree.

ITreeSelectControl<T>.AddBefore(ITreeNode<T>, T, bool) Method

Inserts a sibling immediately before node.

PromptPlusLibrary.ITreeNode<T> AddBefore(PromptPlusLibrary.ITreeNode<T> node, T value, bool disable=false);

Parameters

node PromptPlusLibrary.ITreeNode<T>

The reference sibling. Cannot be null.

value T

The value of the new node. Cannot be null.

disable System.Boolean

When true, the new node cannot be confirmed. Default is false.

Returns

PromptPlusLibrary.ITreeNode<T>

Exceptions

System.ArgumentNullException
When node is null.

System.InvalidOperationException
When node does not belong to this tree.

ITreeSelectControl<T>.AddFirst(T, bool) Method

Adds a first-level node (child of the root) at the beginning.

PromptPlusLibrary.ITreeNode<T> AddFirst(T value, bool disable=false);

Parameters

value T

The value of the new node. Cannot be null.

disable System.Boolean

When true, the new node cannot be confirmed. Default is false.

Returns

PromptPlusLibrary.ITreeNode<T>

Exceptions

System.InvalidOperationException
When the root has not been set yet.

ITreeSelectControl<T>.AddLast(T, bool) Method

Adds a first-level node (child of the root) at the end.

PromptPlusLibrary.ITreeNode<T> AddLast(T value, bool disable=false);

Parameters

value T

The value of the new node. Cannot be null.

disable System.Boolean

When true, the new node cannot be confirmed. Default is false.

Returns

PromptPlusLibrary.ITreeNode<T>
The newly created node so children can be attached to it.

Exceptions

System.InvalidOperationException
When the root has not been set yet.

ITreeSelectControl<T>.ChangeDescription(Func<T,string>) Method

Dynamically updates the prompt description based on the currently selected node.

PromptPlusLibrary.ITreeSelectControl<T> ChangeDescription(System.Func<T,string> value);

Parameters

value System.Func<T,System.String>

A function that receives the current item and returns the description. Cannot be null.

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When value is null.

ITreeSelectControl<T>.ChangeDescriptionAsync(Func<T,Task<string>>) Method

Asynchronous counterpart of ChangeDescription(Func<T,string>). The task is awaited synchronously (blocking) each frame.

PromptPlusLibrary.ITreeSelectControl<T> ChangeDescriptionAsync(System.Func<T,System.Threading.Tasks.Task<string>> value);

Parameters

value System.Func<T,System.Threading.Tasks.Task<System.String>>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When value is null.

ITreeSelectControl<T>.Default(T, bool) Method

Pre-selects an item, expanding the tree down to it when reachable from the root.

PromptPlusLibrary.ITreeSelectControl<T> Default(T value, bool useDefaultHistory=true);

Parameters

value T

useDefaultHistory System.Boolean

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When value is null.

ITreeSelectControl<T>.DefaultMatchBy(Func<T,T,bool>) Method

Sets the item comparator used to locate the default value and the value restored from history within the tree. Required.

PromptPlusLibrary.ITreeSelectControl<T> DefaultMatchBy(System.Func<T,T,bool> comparer);

Parameters

comparer System.Func<T,T,System.Boolean>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When comparer is null.

ITreeSelectControl<T>.EnableHistory(string, Action<IHistoryOptions>) Method

Enables history: the selected value is serialized as JSON and stored, and on the next run the tree is searched (using DefaultMatchBy(Func<T,T,bool>)) for an item that equals the restored value so that it can be pre-selected.

PromptPlusLibrary.ITreeSelectControl<T> EnableHistory(string filename, System.Action<PromptPlusLibrary.IHistoryOptions>? options=null);

Parameters

filename System.String

options System.Action<IHistoryOptions>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When filename is null.

ITreeSelectControl<T>.ExtraInfo(Func<T,string>) Method

Sets an optional extra info selector rendered next to the node text.

PromptPlusLibrary.ITreeSelectControl<T> ExtraInfo(System.Func<T,string?> extraInfoNode);

Parameters

extraInfoNode System.Func<T,System.String>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When extraInfoNode is null.

ITreeSelectControl<T>.ExtraInfoAsync(Func<T,Task<string>>) Method

Asynchronous counterpart of ExtraInfo(Func<T,string>). The task is awaited synchronously (blocking) once per node, per render frame.

PromptPlusLibrary.ITreeSelectControl<T> ExtraInfoAsync(System.Func<T,System.Threading.Tasks.Task<string?>> extraInfoNode);

Parameters

extraInfoNode System.Func<T,System.Threading.Tasks.Task<System.String>>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When extraInfoNode is null.

ITreeSelectControl<T>.Filter(FilterMode) Method

Enables interactive filtering. When the user types a printable character while the tree is in select mode the control switches to filter mode, flattens the whole tree once and applies the requested FilterMode against the node full path (parent chain joined by PathSeparator(char)). Clearing the filter restores the lazy tree view preserving the previous expand/collapse state.

PromptPlusLibrary.ITreeSelectControl<T> Filter(PromptPlusLibrary.FilterMode value);

Parameters

value FilterMode

The FilterMode to apply.

Returns

PromptPlusLibrary.ITreeSelectControl<T>

ITreeSelectControl<T>.Interaction<T1>(IEnumerable<T1>, Action<T1,ITreeSelectControl<T>>) Method

Iterates items and invokes interactionAction for each element, giving the caller a chance to add first-level nodes (and further descendants) programmatically. Equivalent to calling AddLast(T, bool) inside the loop.

PromptPlusLibrary.ITreeSelectControl<T> Interaction<T1>(System.Collections.Generic.IEnumerable<T1> items, System.Action<T1,PromptPlusLibrary.ITreeSelectControl<T>> interactionAction);

Type parameters

T1

Parameters

items System.Collections.Generic.IEnumerable<T1>

interactionAction System.Action<T1,PromptPlusLibrary.ITreeSelectControl<T>>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When items or interactionAction is null.

ITreeSelectControl<T>.InteractionAsync<T1>(IEnumerable<T1>, Func<T1,ITreeSelectControl<T>,Task>) Method

Asynchronous counterpart of Interaction<T1>(IEnumerable<T1>, Action<T1,ITreeSelectControl<T>>). The tasks are awaited sequentially (blocking) so tree construction remains deterministic.

PromptPlusLibrary.ITreeSelectControl<T> InteractionAsync<T1>(System.Collections.Generic.IEnumerable<T1> items, System.Func<T1,PromptPlusLibrary.ITreeSelectControl<T>,System.Threading.Tasks.Task> interactionAction);

Type parameters

T1

Parameters

items System.Collections.Generic.IEnumerable<T1>

interactionAction System.Func<T1,PromptPlusLibrary.ITreeSelectControl<T>,System.Threading.Tasks.Task>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When items or interactionAction is null.

ITreeSelectControl<T>.Options(Action<IControlOptions>) Method

Applies the shared control options (prompt, tooltips, abort behavior).

PromptPlusLibrary.ITreeSelectControl<T> Options(System.Action<PromptPlusLibrary.IControlOptions> options);

Parameters

options System.Action<IControlOptions>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When options is null.

ITreeSelectControl<T>.PageSize(byte) Method

Sets the maximum number of visible rows per page (0 = auto-fit).

PromptPlusLibrary.ITreeSelectControl<T> PageSize(byte value);

Parameters

value System.Byte

Returns

PromptPlusLibrary.ITreeSelectControl<T>

ITreeSelectControl<T>.PathSeparator(char) Method

Sets the character used to compose the full path in the answer line. Default is '/'.

PromptPlusLibrary.ITreeSelectControl<T> PathSeparator(char value);

Parameters

value System.Char

Returns

PromptPlusLibrary.ITreeSelectControl<T>

ITreeSelectControl<T>.PredicateSelected(Func<T,bool>) Method

Sets a validation predicate evaluated when the user presses Enter. When it returns false, the selection is rejected and a generic error is shown.

PromptPlusLibrary.ITreeSelectControl<T> PredicateSelected(System.Func<T,bool> validselect);

Parameters

validselect System.Func<T,System.Boolean>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

ITreeSelectControl<T>.PredicateSelectedAsync(Func<T,Task<bool>>) Method

Sets an asynchronous validation predicate evaluated (blocking) when the user presses Enter.

PromptPlusLibrary.ITreeSelectControl<T> PredicateSelectedAsync(System.Func<T,System.Threading.Tasks.Task<bool>> validselect);

Parameters

validselect System.Func<T,System.Threading.Tasks.Task<System.Boolean>>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Remarks

The asynchronous predicate is evaluated synchronously (blocking) on the UI thread.

ITreeSelectControl<T>.Root(T, bool) Method

Sets the root value shown as the top-level node. Required.

PromptPlusLibrary.ITreeSelectControl<T> Root(T value, bool disable=false);

Parameters

value T

The root value. Cannot be null.

disable System.Boolean

When true, the root cannot be confirmed. Default is false.

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When value is null.

ITreeSelectControl<T>.Run(CancellationToken) Method

Displays the TreeSelect control and blocks until the user confirms or cancels.

PromptPlusLibrary.ResultPrompt<T?> Run(System.Threading.CancellationToken token=default(System.Threading.CancellationToken));

Parameters

token System.Threading.CancellationToken

Returns

PromptPlusLibrary.ResultPrompt<T>

ITreeSelectControl<T>.SelectLeafOnly(bool) Method

When enabled, blocks selection of container nodes (only leaves can be confirmed).

PromptPlusLibrary.ITreeSelectControl<T> SelectLeafOnly(bool value=true);

Parameters

value System.Boolean

Returns

PromptPlusLibrary.ITreeSelectControl<T>

ITreeSelectControl<T>.ShowFullPath(bool) Method

Shows the full path (parent chain) instead of only the entry name in the answer.

PromptPlusLibrary.ITreeSelectControl<T> ShowFullPath(bool value=true);

Parameters

value System.Boolean

Returns

PromptPlusLibrary.ITreeSelectControl<T>

ITreeSelectControl<T>.Styles(TreeSelectStyles, Style) Method

Overrides visual styles for a specific region of the TreeSelect control.

PromptPlusLibrary.ITreeSelectControl<T> Styles(PromptPlusLibrary.TreeSelectStyles styleType, ConsolePlusLibrary.Style style);

Parameters

styleType TreeSelectStyles

style ConsolePlusLibrary.Style

Returns

PromptPlusLibrary.ITreeSelectControl<T>

ITreeSelectControl<T>.TextSelector(Func<T,string>) Method

Sets the display text selector. Required.

PromptPlusLibrary.ITreeSelectControl<T> TextSelector(System.Func<T,string> selector);

Parameters

selector System.Func<T,System.String>

Returns

PromptPlusLibrary.ITreeSelectControl<T>

Exceptions

System.ArgumentNullException
When selector is null.

ITreeSelectControl<T>.ViewOnly(bool) Method

Configures the control for view-only mode, where nodes can be navigated but not selected.

PromptPlusLibrary.ITreeSelectControl<T> ViewOnly(bool value=true);

Parameters

value System.Boolean

If true, enables view-only mode; otherwise, item selection is enabled.

Returns

PromptPlusLibrary.ITreeSelectControl<T>