Package org.jline.builtins
Class Completers.TreeCompleter
java.lang.Object
org.jline.builtins.Completers.TreeCompleter
- All Implemented Interfaces:
Completer
- Enclosing class:
Completers
A completer that supports hierarchical command structures.
This completer allows defining a tree of command nodes, where each node can have its own completer and child nodes. It's useful for implementing command hierarchies where different completions are available at different levels of the command structure.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a node in the completion tree. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Completers.RegexCompleterThe regex completer that handles the tree structureMap of completer names to completer instances -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new TreeCompleter with the specified list of nodes.TreeCompleter(Completers.TreeCompleter.Node... nodes) Creates a new TreeCompleter with the specified nodes. -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddRoots(StringBuilder sb, List<Completers.TreeCompleter.Node> nodes) Adds root nodes to the regex pattern for the completer.voidcomplete(LineReader reader, ParsedLine line, List<Candidate> candidates) Completes the current input line using the tree structure.Creates a new node for the completion tree.
-
Field Details
-
completers
Map of completer names to completer instances -
completer
The regex completer that handles the tree structure
-
-
Constructor Details
-
TreeCompleter
Creates a new TreeCompleter with the specified nodes.- Parameters:
nodes- the root nodes of the completion tree
-
TreeCompleter
Creates a new TreeCompleter with the specified list of nodes.- Parameters:
nodes- the list of root nodes of the completion tree
-
-
Method Details
-
node
Creates a new node for the completion tree.This method accepts various types of objects and constructs a node based on their types:
- String objects are converted to Candidate objects
- Candidate objects are used directly
- Node objects are added as child nodes
- Completer objects are used as the node's completer
- Parameters:
objs- the objects to include in the node- Returns:
- a new Node instance
- Throws:
IllegalArgumentException- if the objects cannot form a valid node
-
addRoots
Adds root nodes to the regex pattern for the completer.This method recursively builds a regex pattern that represents the tree structure of completers, adding each node's completer to the completers map with a unique name.
- Parameters:
sb- the StringBuilder to append the pattern tonodes- the list of nodes to add
-
complete
Completes the current input line using the tree structure.Delegates to the RegexCompleter which handles the tree structure.
-