Tree Interval provides multiple visualization options:
Simple tree visualization with ANSI colors:
tree.visualize()
Output:
┌── Position(0, 100) type=Module
├── Position(10, 40) type=FunctionDef name=hello
└── Position(50, 90) type=ClassDef name=Example
Enhanced visualization using the Rich library:
from tree_interval.rich_printer import RichTreePrinter, RichPrintConfig
# Custom configuration
config = RichPrintConfig(
show_info=True,
show_size=True,
show_position=True,
indent_size=2
)
# Print tree
printer = RichTreePrinter(config)
printer.print_tree(tree)
Visualize tree from any node:
# Using TreeVisualizer
tree.visualize(root=some_leaf)
# Using RichTreePrinter
printer = RichTreePrinter()
printer.print_tree(tree, root=some_leaf)
This allows viewing subtrees starting from any node in the tree structure.
-
Position Format:
- Full position details
- Simple tuple format
- Custom formatting
-
Display Options:
- Node sizes
- Type information
- Children counts
- Custom node info
-
Styling:
- Custom colors
- Bold/italic text
- Guide line styles
- Indentation control