treeprinter

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

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

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 := tp.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 NewWithStyle

func NewWithStyle(style Style) Node

NewWithStyle creates a tree printer like New, permitting customization of the style of the resulting tree.

func (Node) AddEmptyLine

func (n Node) AddEmptyLine()

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

func (Node) AddLine

func (n Node) AddLine(text string)

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

func (Node) Child

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

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

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

func (Node) FormattedRows

func (n Node) FormattedRows() []string

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

func (Node) String

func (n Node) String() string

type Style

type Style int

Style is one of the predefined treeprinter styles.

const (
	// DefaultStyle is the default style. Example:
	//
	//   foo
	//    ├── bar1
	//    │   bar2
	//    │    └── baz
	//    └── qux
	//
	DefaultStyle Style = iota

	// CompactStyle is a compact style, for deeper trees. Example:
	//
	//   foo
	//   ├ bar1
	//   │ bar2
	//   │ └ baz
	//   └ qux
	//
	CompactStyle

	// BulletStyle is a style that shows a bullet for each node, and groups any
	// other lines under that bullet. Example:
	//
	//   • foo
	//   │
	//   ├── • bar1
	//   │   │ bar2
	//   │   │
	//   │   └── • baz
	//   │
	//   └── • qux
	//
	BulletStyle
)

Jump to

Keyboard shortcuts

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