visualize

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package visualize contains a Visualize function that may be used to generate a printable tree representation of a nested set of Node instances. This may be used to visualize an abstract syntax tree, as generated by the parser, but may also be used to visualize other tree-like structures, as long as the elements of those structures implement the parser.Node interface. Different profiles exist that may be used to alter the visual appearance of the visualized tree.

Index

Constants

This section is empty.

Variables

View Source
var (
	ASCII = Profile{
		Start:  '-',
		Last:   '`',
		Branch: '+',
		Skip:   '|',
		Into:   '-',
	}
	Rounded = Profile{
		Start:  '\u2500',
		Last:   '\u2570',
		Branch: '\u251c',
		Skip:   '\u2502',
		Into:   '\u2500',
	}
	Square = Profile{
		Start:  '\u2500',
		Last:   '\u2514',
		Branch: '\u251c',
		Skip:   '\u2502',
		Into:   '\u2500',
	}
)

Pre-configured visual profiles for trees.

Functions

func Visualize

func Visualize(prof Profile, node parser.Node) string

Visualize returns a string containing a visualization of the tree rooted at Node.

Types

type Profile

type Profile struct {
	Start  rune // Joiner character to start a tree at the root
	Last   rune // Joiner character for last child
	Branch rune // Joiner character for a branch
	Skip   rune // Joiner character indicating a node is not a branch
	Into   rune // Joiner character leading into a node
}

Profile represents a visual profile for visualizing the tree.

func (*Profile) Render

func (p *Profile) Render(buf io.Writer, prefix string, node parser.Node, last bool) string

Render renders a node into the buffer with the appropriate tree indicator characters drawn from the profile. It returns the prefix that should be used when rendering children of this node.

Jump to

Keyboard shortcuts

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