treerender

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxPrefixWidthForDepth

func MaxPrefixWidthForDepth(style Style, depth int) int

MaxPrefixWidthForDepth returns the maximum display width of the prefix added by RenderTree for a node at the given depth. This includes the tree edges and the separator. For hot paths, prefer NewPrefixMetrics and PrefixMetrics.MaxWidthForDepth.

Types

type ContinuationIndent

type ContinuationIndent int
const (
	ContinuationIndentTree ContinuationIndent = iota
	ContinuationIndentAnchor
)

type Node

type Node struct {
	Text     string
	Children []*Node
}

type PrefixMetrics

type PrefixMetrics struct {
	// contains filtered or unexported fields
}

PrefixMetrics caches grapheme-aware display widths for a Style so callers that need prefix width at many depths (e.g. plantree wrapping) avoid recomputing tabwrap.StringWidth on every node.

func NewPrefixMetrics

func NewPrefixMetrics(style Style) PrefixMetrics

NewPrefixMetrics precomputes widths for style once; use PrefixMetrics.MaxWidthForDepth per level.

func (PrefixMetrics) MaxWidthForDepth

func (p PrefixMetrics) MaxWidthForDepth(depth int) int

MaxWidthForDepth returns the maximum display width of the prefix added by RenderTree for a node at the given depth. This includes the tree edges and the separator after the edge.

type RenderOptions

type RenderOptions[T any] struct {
	GetContinuationAnchor func(*T) string
	WrapWidth             int
	WrapCondition         *tabwrap.Condition
	ContinuationIndent    ContinuationIndent
}

RenderOptions configures the optional wrapping behavior of RenderTreeWithOptions.

type Row

type Row struct {
	// TreePart is everything rendered before NodeText on each visual line: the ASCII tree drawing
	// plus any continuation padding added by the renderer (for example, hanging-indent spacing).
	// It is joined with newlines using the same line structure as strings.Split(NodeText, "\n").
	TreePart string
	NodeText string
}

func Render

func Render(root *Node, style Style) []Row

Render renders a Node tree. It is equivalent to RenderTree on the same structure.

func RenderTree

func RenderTree[T any](root *T, style Style, getText func(*T) string, getChildren func(*T) []*T) []Row

RenderTree walks an existing tree without copying it into Node, using the supplied accessors.

func RenderTreeWithOptions

func RenderTreeWithOptions[T any](
	root *T,
	style Style,
	getText func(*T) string,
	getChildren func(*T) []*T,
	opts RenderOptions[T],
) ([]Row, error)

RenderTreeWithOptions renders a tree with optional wrapping and continuation-indent behavior. It returns an error if opts contains an invalid ContinuationIndent.

type Style

type Style struct {
	EdgeLink      string
	EdgeMid       string
	EdgeEnd       string
	EdgeSeparator string
	IndentSize    int
}

func CompactStyle

func CompactStyle() Style

func DefaultStyle

func DefaultStyle() Style

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL