tree

package
v0.0.0-...-6052506 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package tree provides functionality to render tree structures

Index

Constants

This section is empty.

Variables

View Source
var DefaultTreeStyle = TreeStyle{
	CharItemVertical:   "│  ",
	CharItemMiddle:     "├─",
	CharItemBottom:     "└─",
	CharChildIndicator: " ●",
}

Functions

This section is empty.

Types

type Renderer

type Renderer[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

Renderer prints a tree from a DirectedAcyclicGraph as a table. Columns: NESTING, COMPONENT, VERSION, PROVIDER, IDENTITY. NESTING shows the tree structure using Unicode box-drawing characters from TreeStyle.

Example output:

NESTING   COMPONENT     VERSION  PROVIDER  IDENTITY
├─ ●      app-frontend  v1.2.0   acme      A
│  ├─ ●   ui-library    v2.1.0   acme      B
│  │  └─  icons         v1.0.0   other     C
│  └─     api-client    v3.0.0   acme      D
├─ ●      app-backend   v2.0.0   acme      X
│  └─     database      v1.1.0   acme      Y
└─        cache-layer   v0.9.0   other     Z

func New

func New[T cmp.Ordered](ctx context.Context, dag *syncdag.DirectedAcyclicGraph[T], opts ...RendererOption[T]) *Renderer[T]

New creates a new Renderer for the given DirectedAcyclicGraph.

func (*Renderer[T]) Render

func (t *Renderer[T]) Render(ctx context.Context, writer io.Writer) error

Render renders the tree structure starting from the root ID. It writes the output to the provided writer.

type RendererOption

type RendererOption[T cmp.Ordered] func(*RendererOptions[T])

RendererOption is a function that modifies the RendererOptions.

func WithRoots

func WithRoots[T cmp.Ordered](roots ...T) RendererOption[T]

WithRoots sets the roots for the Renderer.

func WithVertexSerializer

func WithVertexSerializer[T cmp.Ordered](serializer VertexSerializer[T]) RendererOption[T]

WithVertexSerializer sets the VertexSerializer for the Renderer.

func WithVertexSerializerFunc

func WithVertexSerializerFunc[T cmp.Ordered](serializerFunc func(*syncdag.Vertex[T]) (Row, error)) RendererOption[T]

WithVertexSerializerFunc sets the VertexSerializer based on a function.

type RendererOptions

type RendererOptions[T cmp.Ordered] struct {
	// VertexSerializer serializes a vertex into a Row.
	VertexSerializer VertexSerializer[T]
	// Roots are the root vertices of the tree to render.
	Roots []T
	// TableStyle allows customizing the go-pretty table style used by the renderer.
	TableStyle table.Style
}

RendererOptions defines the options for the tree Renderer.

type Row

type Row struct {
	Component string
	Version   string
	Provider  string
	Identity  string
}

Row represents a single rendered row

type TreeStyle

type TreeStyle struct {
	// CharItemVertical is the character used for vertical lines (│)
	CharItemVertical string
	// CharItemMiddle is the character used for middle branch connectors (├─)
	CharItemMiddle string
	// CharItemBottom is the character used for bottom branch connectors (└─)
	CharItemBottom string
	// CharChildIndicator is the character used to indicate nodes with children (●)
	CharChildIndicator string
}

TreeStyle defines the Unicode characters used for rendering tree structures.

type VertexSerializer

type VertexSerializer[T cmp.Ordered] interface {
	Serialize(*syncdag.Vertex[T]) (Row, error)
}

VertexSerializer is an interface that defines a method to serialize a vertex.

type VertexSerializerFunc

type VertexSerializerFunc[T cmp.Ordered] func(*syncdag.Vertex[T]) (Row, error)

func (VertexSerializerFunc[T]) Serialize

func (f VertexSerializerFunc[T]) Serialize(v *syncdag.Vertex[T]) (Row, error)

Jump to

Keyboard shortcuts

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