cockroach: github.com/cockroachdb/cockroach/pkg/util/treeprinter Index | Files

package treeprinter

import "github.com/cockroachdb/cockroach/pkg/util/treeprinter"

Index

Package Files

tree_printer.go

type Node Uses

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

Node is a handle associated with a specific depth in a tree. See below for sample usage.

func New Uses

func New() Node

New creates a tree printer and returns a sentinel node reference which should be used to add the root. Sample usage:

tp := New()
root := n.Child("root")
root.Child("child-1")
root.Child("child-2").Child("grandchild\ngrandchild-more-info")
root.Child("child-3")

fmt.Print(tp.String())

Output:

root
 ├── child-1
 ├── child-2
 │    └── grandchild
 │        grandchild-more-info
 └── child-3

Note that the Child calls can't be rearranged arbitrarily; they have to be in the order they need to be displayed (depth-first pre-order).

func NewWithIndent Uses

func NewWithIndent(leftPad, rightPad bool, edgeLength int) Node

NewWithIndent creates a tree printer like New, permitting customization of the width of the outputted tree. leftPad controls whether the tree lines are padded from the first character of their parent. rightPad controls whether children are separated from their edges by a space. edgeLength controls how many characters wide each edge is.

func (Node) AddEmptyLine Uses

func (n Node) AddEmptyLine()

AddEmptyLine adds an empty line to the output; used to introduce vertical spacing as needed.

func (Node) AddLine Uses

func (n Node) AddLine(v string)

AddLine adds a new line to a child node without an edge.

func (Node) Child Uses

func (n Node) Child(text string) Node

Child adds a node as a child of the given node. Multi-line strings are supported with appropriate indentation.

func (Node) Childf Uses

func (n Node) Childf(format string, args ...interface{}) Node

Childf adds a node as a child of the given node.

func (Node) FormattedRows Uses

func (n Node) FormattedRows() []string

FormattedRows returns the formatted rows. Can only be called on the result of treeprinter.New.

func (Node) String Uses

func (n Node) String() string

Package treeprinter imports 3 packages (graph) and is imported by 19 packages. Updated 2019-09-15. Refresh now. Tools for package owners.