Documentation ¶
Index ¶
- Constants
- func New() tea.Model
- type ItemHolder
- type KeyMap
- type Tree
- func (t *Tree) AddChildren(i ...*TreeItem) ItemHolder
- func (t *Tree) Blur() tea.Cmd
- func (t *Tree) CountVisibleItems() int
- func (t *Tree) Error() error
- func (t *Tree) Focus() tea.Cmd
- func (t *Tree) GetItems() []*TreeItem
- func (t *Tree) GetKey() string
- func (t *Tree) GetParent() ItemHolder
- func (t *Tree) GetPath() []string
- func (t *Tree) GetValue() any
- func (t *Tree) Init() tea.Cmd
- func (t *Tree) KeyBinds() []key.Binding
- func (t *Tree) Refresh()
- func (t *Tree) Run() error
- func (t *Tree) ScrollDown(n int)
- func (t *Tree) ScrollUp(n int)
- func (t *Tree) SelectFirst()
- func (t *Tree) SelectLast()
- func (t *Tree) SelectNext()
- func (t *Tree) SelectPrevious()
- func (t *Tree) SetActive(ti *TreeItem)
- func (t *Tree) Skip() bool
- func (t *Tree) ToggleChild()
- func (t *Tree) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (t *Tree) View() string
- func (t *Tree) WithAccessible(accessible bool) huh.Field
- func (t *Tree) WithHeight(height int) huh.Field
- func (t *Tree) WithKeyMap(k *huh.KeyMap) huh.Field
- func (t *Tree) WithPosition(p huh.FieldPosition) huh.Field
- func (t *Tree) WithTheme(theme *huh.Theme) huh.Field
- func (t *Tree) WithWidth(width int) huh.Field
- type TreeItem
- func (ti *TreeItem) AddChildren(children ...*TreeItem) ItemHolder
- func (ti *TreeItem) CloseChildren()
- func (ti *TreeItem) CountItemAndChildren() int
- func (ti *TreeItem) GetItems() []*TreeItem
- func (ti *TreeItem) GetParent() ItemHolder
- func (ti *TreeItem) GetPath() []string
- func (ti *TreeItem) Icon() string
- func (ti *TreeItem) IconStyle() lipgloss.Style
- func (ti *TreeItem) Init() tea.Cmd
- func (ti *TreeItem) LabelStyle() lipgloss.Style
- func (ti *TreeItem) OpenChildren()
- func (ti *TreeItem) Refresh()
- func (ti *TreeItem) SelectLast()
- func (ti *TreeItem) SelectNext()
- func (ti *TreeItem) SelectPrevious()
- func (ti *TreeItem) SetSelectFunc(sf func(*TreeItem))
- func (ti *TreeItem) ToggleChildren()
- func (ti *TreeItem) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (ti *TreeItem) View() string
- func (ti *TreeItem) ViewScrolled(viewtop, curline, bottomline int) (int, string)
Constants ¶
const ChevronDown = "\U000F0140"
const ChevronRight = "\U000F0142"
const NoChevron = " "
This is the material design icon in the nerdfont/material symbols set, as found in https://pictogrammers.com/library/mdi/
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ItemHolder ¶
type ItemHolder interface { GetItems() []*TreeItem // GetPath - recursively search through the parent hierarchy and return the name of each item // They will be ordered from oldest ancestor to most recent descendant. The item itself will // be the last one in the list GetPath() []string AddChildren(...*TreeItem) ItemHolder GetParent() ItemHolder Refresh() // This tells the item holder to delete all of its children and re-read them. }
type KeyMap ¶
type KeyMap struct { Space key.Binding GoToTop key.Binding GoToLast key.Binding Down key.Binding Up key.Binding PageUp key.Binding PageDown key.Binding Back key.Binding Open key.Binding Select key.Binding }
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
type Tree ¶
type Tree struct { sync.Mutex Viewtop int // for scrolling Width int Height int ClosedChildrenSymbol string OpenChildrenSymbol string ActiveItem *TreeItem ActiveLine int // Which line, (from 0..Height) is the cursor on? Items []*TreeItem `json:"-"` Style lipgloss.Style KeyMap KeyMap // contains filtered or unexported fields }
func (*Tree) AddChildren ¶
func (t *Tree) AddChildren(i ...*TreeItem) ItemHolder
func (*Tree) CountVisibleItems ¶
func (*Tree) GetParent ¶
func (t *Tree) GetParent() ItemHolder
Returning nil here means you can't go "up" outside of the tree widget, so if this widget is embedded with others, this will prevent getting out of the tree.
func (*Tree) GetPath ¶
This GetPath() represents the path from the root of the tree to here. Since this IS the root of the tree, then it must return nothing.
func (*Tree) ScrollDown ¶
ScrollDown moves the "display" area down the virtual list. This actually looks like scrolling up ((the items move up the screen) Not sure if this is counterintuitive or not
func (*Tree) SelectFirst ¶
func (t *Tree) SelectFirst()
func (*Tree) SelectLast ¶
func (t *Tree) SelectLast()
func (*Tree) SelectNext ¶
func (t *Tree) SelectNext()
SelectNext is like SelectPrevious, but the other way
func (*Tree) SelectPrevious ¶
func (t *Tree) SelectPrevious()
SelectPrevious - selects the previous TreeItem. This involves first getting the parent and then telling the parent to select the previous item from the current selection. If we're already at the first child, then we go to the grandparent and select the previous parent item from us, and then we descend to the most open child and activate that.rune
func (*Tree) ToggleChild ¶
func (t *Tree) ToggleChild()
ToggleChild will toggle the open/closed state of the current selection. This only has meaning if there are actually children
func (*Tree) WithAccessible ¶
WithAccessible sets the accessible mode of the input field.
func (*Tree) WithHeight ¶
WithHeight sets the height of the input field.
func (*Tree) WithKeyMap ¶
WithKeyMap sets the keymap on an input field.
func (*Tree) WithPosition ¶
func (t *Tree) WithPosition(p huh.FieldPosition) huh.Field
WithPosition sets the position of the input field.
type TreeItem ¶
type TreeItem struct { sync.Mutex Name string Children []*TreeItem CanHaveChildren bool // CanHaveChildren: By setting this to True, you say that this item can have children. This allows for the implementation of a lazy loader, when you supply an Open() function. This affects how the item is rendered. Open bool Data interface{} OpenFunc func(*TreeItem) `json:"-"` CloseFunc func(*TreeItem) `json:"-"` // contains filtered or unexported fields }
func (*TreeItem) AddChildren ¶
func (ti *TreeItem) AddChildren(children ...*TreeItem) ItemHolder
AddChildren - adds a list of children to an item, and then returns the item AddChild - adds a child item to the item. Adding a child will result in the automatic inclusion of the collapse chevron
func (*TreeItem) CloseChildren ¶
func (ti *TreeItem) CloseChildren()
func (*TreeItem) CountItemAndChildren ¶
CountItemAndChildren - returns the count of this item plus any visible children.
func (*TreeItem) GetParent ¶
func (ti *TreeItem) GetParent() ItemHolder
func (*TreeItem) LabelStyle ¶
func (*TreeItem) OpenChildren ¶
func (ti *TreeItem) OpenChildren()
func (*TreeItem) SelectLast ¶
func (ti *TreeItem) SelectLast()
SelectLast - starting from the current Item, descend in the last child of the last child and set that as the active item. Also need to set the topline ff
func (*TreeItem) SelectNext ¶
func (ti *TreeItem) SelectNext()
We're being told to select the next item relative to our current position.
func (*TreeItem) SelectPrevious ¶
func (ti *TreeItem) SelectPrevious()
SelectPrevious - this is being invoked on a TreeItem that is currently selected and the user wants to move up to the previous selection. This will involve recursively going up the tree until we find the one to select or we get to the top
func (*TreeItem) SetSelectFunc ¶
func (*TreeItem) ToggleChildren ¶
func (ti *TreeItem) ToggleChildren()