tree

package
v0.0.0-...-0a8b275 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alignment

type Alignment int

Alignment declares alignment constants as integers

const (
	// AlignLeft is the text left alignment constant
	AlignLeft Alignment = iota
	// AlignRight is the text right alignment constant
	AlignRight
)

type Cell

type Cell struct {
	Text string
	// contains filtered or unexported fields
}

Cell is a colored and aligned cell in a column. Cells are the result of phrases wrapping to respect the column width. The color and alignment are inhérited from the origin TextBlock.

type Column

type Column struct {
	Text  []*TextBlock
	Cells []*Cell
	Color color.Attribute
	Align Alignment
	// contains filtered or unexported fields
}

Column exposes a method to add extra text blocks

func (*Column) AddText

func (c *Column) AddText(text string) *TextBlock

AddText adds a colored and aligned phrase to this column.

type Node

type Node struct {
	Forest *Tree
	Parent *Node
	// contains filtered or unexported fields
}

Node exposes methods to add columns.

func (*Node) AddColumn

func (t *Node) AddColumn() *Column

AddColumn adds and returns a column to the node. Phrases can be added through the returned Column object.

func (*Node) AddNode

func (t *Node) AddNode() *Node

AddNode adds and returns a new Node, child of this node.

func (*Node) IsEmpty

func (t *Node) IsEmpty() bool

IsEmpty returns true if the node has one or more columns

func (*Node) Load

func (t *Node) Load(data interface{}, title string)

Load loads data in the node

Example dataset:

{
    "data": [
        {
            "text": "node1",
            "color": color.BOLD
        }
    ],
    "children": [
        {
            "data": [
                {
                    "text": "node2"
                },
                {
                    "text": "foo",
                    "color": color.RED
                }
            ],
            "children": [
            ]
        }
    ]
}

would be rendered as:

node1 `- node2 foo

func (*Node) PlugNode

func (t *Node) PlugNode(child *Node)

PlugNode adds and existing Node as child of this node.

func (*Node) PlugTree

func (t *Node) PlugTree(n *Tree)

PlugTree add an existing tree head Node as child this node.

func (*Node) String

func (t *Node) String() string

type TextBlock

type TextBlock struct {
	Text string
	// contains filtered or unexported fields
}

TextBlock is a colored and aligned phrase in a column.

func (*TextBlock) SetAlign

func (t *TextBlock) SetAlign(align Alignment) *TextBlock

SetAlign sets the text block alignment and returns the textBlock ref so the caller can chain AddText("").SetColor().SetAlign()

func (*TextBlock) SetColor

func (t *TextBlock) SetColor(textColor color.Attribute) *TextBlock

SetColor sets the text block color and returns the textBlock ref so the caller can chain AddText("").SetColor().SetAlign()

type Tree

type Tree struct {
	Separator   string
	Widths      []Width
	ForcedWidth int
	// contains filtered or unexported fields
}

Tree exposes methods to populate and print a Tree.

Example:

Tree := tree.New() overallNode := Tree.AddNode() overallNode.AddColumn("overall")

node := overallNode.AddNode() node.AddColumn("avail") node.AddColumn() node.AddColumn("up", color.Green) node = node.AddNode() node.AddColumn("res#id") node.AddColumn("....") node.AddColumn("up", color.Green) col := node.AddColumn("label") col.AddText("warn", color.Yellow) col.AddText("err", color.Red)

func New

func New() *Tree

New allocates a new tree and returns a reference.

func (*Tree) AddColumn

func (t *Tree) AddColumn() *Column

AddColumn adds and returns a column to the head node. Phrases can be added through the returned Column object.

func (*Tree) AddNode

func (t *Tree) AddNode() *Node

AddNode adds and returns a new Node, child of this node.

func (*Tree) Head

func (t *Tree) Head() *Node

Head return the tree head Node reference.

func (*Tree) IsEmpty

func (t *Tree) IsEmpty() bool

IsEmpty returns true if the tree head node has no children.

func (*Tree) PlugNode

func (t *Tree) PlugNode(n *Node)

PlugNode add an existing Node as child of the head node of the tree

func (*Tree) PlugTree

func (t *Tree) PlugTree(n *Tree)

PlugTree add an existing tree head Node as child of the head node of the tree

func (*Tree) Render

func (t *Tree) Render() string

Render returns the string representation of the tree.

Each node is considered tabular, with cells content aligned and wrapped.

The widths parameter can used to set per-column min/max or exact widths:

widths = [

(0, 10),   # col1: min 0, max 10 chars
None,      # col2: no constraints, auto detect
10         # col3: exactly 10 chars

]

type Width

type Width struct {
	Min   int
	Max   int
	Exact int
}

Width describes a user-defined column width preference

Jump to

Keyboard shortcuts

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