...

Package treeprint

import "github.com/xlab/treeprint"
Overview
Index

Overview ▾

Package treeprint provides a simple ASCII tree composing tool.

Variables

IndentSize is the number of spaces per tree level.

var IndentSize = 3

func Repr

func Repr(v interface{}) string

type EdgeType

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

type FmtFunc

type FmtFunc func(name string, v interface{}) (string, bool)

type MetaValue

MetaValue defines any meta value

type MetaValue interface{}

type Node

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

func (*Node) AddBranch

func (n *Node) AddBranch(v Value) 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

NodeVisitor function type for iterating over nodes

type NodeVisitor func(item *Node)

type StructTreeOption

type StructTreeOption int
const (
    StructNameTree StructTreeOption = iota
    StructValueTree
    StructTagTree
    StructTypeTree
    StructTypeSizeTree
)

type Tree

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

type Tree interface {
    // 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)
}

func FromStruct

func FromStruct(v interface{}, opt ...StructTreeOption) (Tree, error)

func FromStructWithMeta

func FromStructWithMeta(v interface{}, fmtFunc FmtFunc) (Tree, error)

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

Value defines any value

type Value interface{}