menu

package
v3.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FocusModel

type FocusModel interface {
	tea.Model
	SetFocus(bool)
	IsFocused() bool
	// Reset should reset the model to its initial state.
	Reset()
}

type Item

type Item struct {
	// ID is an arbitrary ID, up to caller.
	ID string
	// Separator is a flag that determines whether the item is a separator or
	// not.
	Separator bool
	// Name is the name of the Item, will be displayed in the menu.
	Name string
	// Help is the help text for the item, that will be shown when the
	// item is highlighted.
	Help string
	// Model is any model that should be displayed when the item is selected,
	// or executed when the user presses enter.
	Model FocusModel
	// Preview suggests that the Model should attempt to show the preview
	// of this item.
	Preview bool
	// Validate determines whether the item is disabled or not. It should
	// complete in reasonable time, as it is called on every render.  The
	// return error is used in the description for the item.
	Validate func() error // when to enable the item
}

Item is an item in a menu.

func (Item) DisabledReason

func (m Item) DisabledReason() string

func (Item) IsDisabled

func (m Item) IsDisabled() bool

type Keymap

type Keymap struct {
	Up     key.Binding
	Down   key.Binding
	Select key.Binding
	Quit   key.Binding
}

func DefaultKeymap

func DefaultKeymap() *Keymap

func (*Keymap) Bindings

func (k *Keymap) Bindings() []key.Binding

type Model

type Model struct {
	// Selected will be set to the selected item from the items.
	Selected  Item
	Cancelled bool

	Style  *Style
	Keymap *Keymap
	// contains filtered or unexported fields
}

func New

func New(title string, items []Item, preview bool) *Model

func (*Model) Init

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

func (*Model) IsFocused

func (m *Model) IsFocused() bool

func (*Model) Select

func (m *Model) Select(id string)

func (*Model) SetFocus

func (m *Model) SetFocus(b bool)

func (*Model) Update

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

func (*Model) View

func (m *Model) View() string

type Style

type Style struct {
	Focused StyleSet
	Blurred StyleSet
}

func DefaultStyle

func DefaultStyle() *Style

type StyleSet

type StyleSet struct {
	Border       lipgloss.Style
	Title        lipgloss.Style
	Description  lipgloss.Style
	Cursor       lipgloss.Style
	Item         lipgloss.Style
	ItemSelected lipgloss.Style
	ItemDisabled lipgloss.Style
}

Jump to

Keyboard shortcuts

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