recursivelist

package
v0.0.0-...-c424ded Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpandCollapse

type ExpandCollapse[T ItemWrapper[T]] struct {
	Affected  ListItem[T]
	Collapsed bool
}

type ItemAdded

type ItemAdded struct {
	InsertedAt int
}

type ItemDeleted

type ItemDeleted struct {
	DeletedIndex int
}

type ItemWrapper

type ItemWrapper[T any] interface {
	list.Item
	// finds and returns the index of the child
	// within the current element's children
	Find(T) int
	// should find and return the index of the
	// current element within its parent
	IndexWithinParent() int
	// should return this item's children
	GetChildren() []T
	// overwrites the value's children with the given argument.
	SetChildren([]T)
	// should return the current element's parent.
	GetParent() *T
	// should set the item's parent to the argument.
	SetParent(*T)
	// since `value` is not exported from the `ListItem`,
	// we need a wrapper function to access it.
	Value() *T
	// returns how deeply nested the current node is, as an int.
	// i'd recommend calculating this by checking that `Parent`
	// is not null in a for loop.
	Lvl() int
	// adds an element to this item's children.
	Add(int, T)
	// same as Add() but can receive more than one argument!
	AddMulti(int, ...T)
	// Removes child at specified index and returns it
	Remove(int) T
	// Returns a string representation of this item.
	ToString() string
}

type KeyMap

type KeyMap struct {
	Expand key.Binding
	Choose key.Binding
}
var DefaultKeys KeyMap = KeyMap{
	Expand: key.NewBinding(
		key.WithKeys("/"),
		key.WithHelp("/", "expand/collapse item"),
	),
	Choose: key.NewBinding(
		key.WithKeys(" ", tea.KeyEnter.String()),
		key.WithHelp("<space>/↲", "choose item"),
	),
}

type ListItem

type ListItem[T ItemWrapper[T]] struct {
	ParentModel *Model[T]
	// this is a recursive struct, meaning that it can
	// have 0 or more child elements, which can have 0
	// or more child elements, and so on
	Children *[]ListItem[T]
	// if it is a top level item, this field will be `nil`.
	// otherwise contains the element that contains the
	// current item
	Parent *ListItem[T]
	// contains filtered or unexported fields
}

func (*ListItem[T]) Add

func (i *ListItem[T]) Add(item T, index int) ListItem[T]

func (*ListItem[T]) AddMulti

func (i *ListItem[T]) AddMulti(index int, items ...T)

func (ListItem[T]) Expanded

func (i ListItem[T]) Expanded() bool

func (ListItem[T]) FilterValue

func (r ListItem[T]) FilterValue() string

func (ListItem[T]) Flatten

func (r ListItem[T]) Flatten() []ListItem[T]

func (ListItem[T]) GetChildren

func (r ListItem[T]) GetChildren() []ListItem[T]

func (ListItem[T]) GetParent

func (r ListItem[T]) GetParent() *ListItem[T]

func (ListItem[T]) IndexWithinParent

func (r ListItem[T]) IndexWithinParent() int

func (ListItem[T]) Point

func (i ListItem[T]) Point() *ListItem[T]

func (ListItem[T]) RModify

func (r ListItem[T]) RModify(fnn func(ListItem[T]))

func (*ListItem[T]) SetExpanded

func (i *ListItem[T]) SetExpanded(v bool) tea.Cmd

func (ListItem[T]) TotalBeneath

func (r ListItem[T]) TotalBeneath() int

func (*ListItem[T]) Value

func (r *ListItem[T]) Value() *T

type ListOptions

type ListOptions struct {
	Keymap            list.KeyMap
	Styles            list.Styles
	Title             string
	FilteringEnabled  bool
	InfiniteScrolling bool
}

type Model

type Model[T ItemWrapper[T]] struct {
	List    list.Model
	Options Options
	// contains filtered or unexported fields
}

func New

func New[T ItemWrapper[T]](items []T, delegate list.ItemDelegate, options Options) Model[T]

func (*Model[T]) AddToRoot

func (m *Model[T]) AddToRoot(argument ...T)

func (*Model[T]) Flatten

func (m *Model[T]) Flatten() (tea.Cmd, []list.Item)

func (Model[T]) Init

func (m Model[T]) Init() tea.Cmd

func (*Model[T]) NewItem

func (m *Model[T]) NewItem(item T) ListItem[T]

creates a new ListItem. note that this does NOT append it to m.items; you have to do that yourself with m.AddToRoot()

func (*Model[T]) SetSize

func (m *Model[T]) SetSize(w, h int)

func (Model[T]) Update

func (m Model[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Model[T]) View

func (m Model[T]) View() string

type Options

type Options struct {
	ClosedPrefix string
	OpenPrefix   string
	ListOptions  ListOptions
	Expandable   bool
	Width        int
	Height       int
	Keymap       KeyMap
}
var DefaultOptions Options = Options{
	ClosedPrefix: ">",
	OpenPrefix:   "⌵",
	Width:        600,
	Height:       250,
	Expandable:   true,
	Keymap:       DefaultKeys,
}

func (*Options) SetExpandable

func (o *Options) SetExpandable(v bool)

Jump to

Keyboard shortcuts

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