fliptree

package
v0.1.0-beta4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package fliptree renders a tree of nodes as text in reverse: children first, then parent.

For example: given main -> {feat1 -> feat1.1, feat2 -> feat2.1} The tree would look like this:

  ┌── feat2.1
┌─┴ feat2
│ ┌── feat1.1
├─┴ feat1
main

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(w io.Writer, g Graph, opts Options) error

Write renders the tree of nodes in g.

Types

type CycleError

type CycleError struct {
	// Path from root node to the node that formed the cycle.
	Path []int
}

CycleError is returned when a cycle is detected in the tree.

func (*CycleError) Error

func (e *CycleError) Error() string

type Graph

type Graph struct {
	// Roots are the nodes at which we want to start rendering the tree.
	// Each root will be rendered as a separate tree.
	Roots []string

	// View returns the text for the node.
	// The value may be multiline, and may have its own styling.
	View func(string) string

	// Edges returns the nodes that are directly reachable
	// from the given node.
	Edges func(string) []string
}

Graph defines a directed graph.

type Options

type Options struct {
	Style *Style

	// If non-nil, this map will be filled with the positions
	// of each node in the rendered tree.
	//
	// The key is the node name, and the value is 0-indexed line number
	// in the rendered tree where the node appears.
	Offsets map[string]int
}

Options configure the rendering of the tree.

type Style

type Style struct {
	// Joint defines how the connecting joints between nodes are rendered.
	Joint lipgloss.Style
}

Style configures the visual appearance of the tree.

func DefaultStyle

func DefaultStyle() *Style

DefaultStyle returns the default style for rendering trees.

Jump to

Keyboard shortcuts

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