navstack

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 4 Imported by: 9

Documentation

Overview

Package Navstack manages a stack of NavigationItems which can be pushed or popped from the stack. The top most stack navigation item is used by [BubbleTea] to Update and renders it's View. When pushing and popping items from the stack, the new view to be presented is sent a tea.WindowSizeMsg to ensure it's view can be presented correctly. When the last item is popped from the stack the application will quit. NavigationItem models which implement the Closable interface will have their Close method called when they are popped from the stack. This is useful for cleaning up resources that may not be garbage collected when a view a no longer needed. [BubbleTea]: https://github.com/charmbracelet/bubbletea

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PopNavigationCmd added in v0.1.2

func PopNavigationCmd() tea.Cmd

func PushNavigationCmd added in v0.1.2

func PushNavigationCmd(item NavigationItem) tea.Cmd

Types

type Closable

type Closable interface {
	Close() error
}

Closable is an interface for models that have resources that need to be cleaned up when they are no longer needed. The navigation stack checks for this interface when popping items.

type Model

type Model struct {
	// contains filtered or unexported fields
}

func New

func New(w *window.Model) Model

New creates a new navigation stack model. The window is used to constrain the view within the container of the navigation stack.

func (*Model) Clear added in v0.1.2

func (m *Model) Clear() error

Clear pops all the items from the stack.

func (Model) Init

func (m Model) Init() tea.Cmd

func (*Model) Pop

func (m *Model) Pop() tea.Cmd

Pop removes the top most navigation item from the stack. If the item implements the Closable interface the Close method is called. The new top most item on the stack is given a tea.WindowSizeMsg to ensure it's view can be presented correctly. If there are no more items on the stack the application will quit.

func (*Model) Push

func (m *Model) Push(item NavigationItem) tea.Cmd

Push pushes a new navigation item onto the stack. The new navigation item is given a tea.WindowSizeMsg to ensure it's view can be presented correctly. The item's Init method is called and resulting command is processed by [BubbleTea]. If top item's model implements the Closable interface the Close method is called. This new item will be the top most item on the stack and thus will be rendered.

func (Model) StackSummary

func (m Model) StackSummary() []string

StackSummary returns a list of titles for each item on the stack. This is currently used by the breadcrumb component to render the breadcrumb trail.

func (Model) Top

func (m Model) Top() *NavigationItem

Top returns the top most navigation item on the stack.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) tea.Cmd

Update processes messages for the top most navigation item on the stack.

func (Model) View

func (m Model) View() string

View renders the top most navigation item on the stack.

type NavigationItem struct {
	Title string
	Model tea.Model
}

NavigationItem is a component that represents an item in the navigation stack. The top most item on the stack is rendered.

func (n NavigationItem) Init() tea.Cmd

Init is called when the item is pushed onto the stack.

func (n NavigationItem) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update receives messages when the item is on top of the stack.

func (n NavigationItem) View() string

View is calledn when the item is on top of the stack.

type PopNavigation

type PopNavigation struct{}

PopNavigation is a message that can be sent to the menu model to de-select the currently selected menu choice

type PushNavigation

type PushNavigation struct {
	Item NavigationItem
}

type ReloadCurrent

type ReloadCurrent struct{}

ReloadCurrent is a message that can be sent to the menu model to reload the currently selected menu choice

Jump to

Keyboard shortcuts

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