treeprint

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package treeprint provides a simple ASCII tree composing tool. Forked from: https://github.com/xlab/treeprint

Index

Constants

This section is empty.

Variables

View Source
var IndentSize = 3

IndentSize is the number of spaces per tree level.

Functions

This section is empty.

Types

type EdgeType

type EdgeType string
var (
	EdgeTypeLink EdgeType = "│"
	EdgeTypeMid  EdgeType = "├──"
	EdgeTypeEnd  EdgeType = "└──"
)

type MetaValue

type MetaValue interface{}

MetaValue defines any meta value

type Node

type Node struct {
	Root  *Node
	IsGap bool
	Meta  MetaValue
	Value Value
	Nodes []*Node
}

func (*Node) AddBranch

func (n *Node) AddBranch(v Value) Tree

func (*Node) AddGap

func (n *Node) AddGap() Tree

func (*Node) AddMetaBranch

func (n *Node) AddMetaBranch(meta MetaValue, v Value) Tree

func (*Node) AddMetaNode

func (n *Node) AddMetaNode(meta MetaValue, v Value) Tree

func (*Node) AddNode

func (n *Node) AddNode(v Value) Tree

func (*Node) Branch

func (n *Node) Branch() Tree

func (*Node) Bytes

func (n *Node) Bytes() []byte

func (*Node) FindByMeta

func (n *Node) FindByMeta(meta MetaValue) Tree

func (*Node) FindByValue

func (n *Node) FindByValue(value Value) Tree

func (*Node) FindLastNode

func (n *Node) FindLastNode() Tree

func (*Node) SetMetaValue

func (n *Node) SetMetaValue(meta MetaValue)

func (*Node) SetValue

func (n *Node) SetValue(value Value)

func (*Node) String

func (n *Node) String() string

func (*Node) VisitAll

func (n *Node) VisitAll(fn NodeVisitor)

type NodeVisitor

type NodeVisitor func(item *Node)

NodeVisitor function type for iterating over nodes

type Tree

type Tree interface {
	// AddGap adds a new gap to a branch.
	AddGap() Tree
	// AddNode adds a new Node to a branch.
	AddNode(v Value) Tree
	// AddMetaNode adds a new Node with meta value provided to a branch.
	AddMetaNode(meta MetaValue, v Value) Tree
	// AddBranch adds a new branch Node (a level deeper).
	AddBranch(v Value) Tree
	// AddMetaBranch adds a new branch Node (a level deeper) with meta value provided.
	AddMetaBranch(meta MetaValue, v Value) Tree
	// Branch converts a leaf-Node to a branch-Node,
	// applying this on a branch-Node does no effect.
	Branch() Tree
	// FindByMeta finds a Node whose meta value matches the provided one by reflect.DeepEqual,
	// returns nil if not found.
	FindByMeta(meta MetaValue) Tree
	// FindByValue finds a Node whose value matches the provided one by reflect.DeepEqual,
	// returns nil if not found.
	FindByValue(value Value) Tree
	//  returns the last Node of a tree
	FindLastNode() Tree
	// String renders the tree or subtree as a string.
	String() string
	// Bytes renders the tree or subtree as byteslice.
	Bytes() []byte

	SetValue(value Value)
	SetMetaValue(meta MetaValue)

	// VisitAll iterates over the tree, branches and nodes.
	// If need to iterate over the whole tree, use the root Node.
	// Note this method uses a breadth-first approach.
	VisitAll(fn NodeVisitor)
}

Tree represents a tree structure with leaf-nodes and branch-nodes.

func New

func New() Tree

New Generates new tree

func NewWithRoot

func NewWithRoot(root Value) Tree

NewWithRoot Generates new tree with the given root value

type Value

type Value interface{}

Value defines any value

Jump to

Keyboard shortcuts

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