Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaxPrefixWidthForDepth ¶
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 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 ¶
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.