trees

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package trees provides a simple text-base tree view that uses ANSI escape codes to re-write parts of the tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node interface {
	// AddChild adds a new child Node to the receiver.
	AddChild() (child Node)

	// Update displays content on the Node's line, replacing any content set by previous calls to Update. There must
	Update(line string)
}

Node is a single node in a Tree (including the Tree itself).

type Tree

type Tree struct {
	// Indent is prepended to each Node the number of times required to display the tree's hierarchy.
	Indent string

	// Prefix is prepended to each of the tree's descendent Nodes, after Indent but before the Node's contents.
	Prefix string

	// TruncatedLineSuffix is appended to lines that have been truncated due to being longer than the width of the
	// terminal.
	TruncatedLineSuffix string
	// contains filtered or unexported fields
}

Tree writes, and re-writes, a tree of information to the given io.Writer using ANSI cursor positioning. Indent and Prefix control how the tree is formed. Second level and below are prefixed with Prefix, and third level and below are prefixed with Indent * (level - 2), followed by Prefix.

For example, with Indent of "--" and Prefix of "+ ", you might see:

Heading 1
+ Heading 2
--+ Heading 3
----+ Heading 4

A zero Tree is not valid. Use New or NewWithWriter.

func New

func New() *Tree

New returns a new Tree that will write to os.Stdout.

func NewWithWriter

func NewWithWriter(writer io.Writer) (tree *Tree)

NewWithWriter returns a new Tree that will write to writer.

func (Tree) AddChild

func (n Tree) AddChild() (child Node)

AddChild implements Node.

func (Tree) Update

func (n Tree) Update(content string)

Update implements Node.

Jump to

Keyboard shortcuts

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