menu

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: 8 Imported by: 5

Documentation

Overview

Package Menu takes a list of choices allowing the user to select a component to push onto the navigation stack. Each choice has a title and a description and a component model implementing tea.Model. tea.Model https://github.com/charmbracelet/bubbletea/blob/a256e76ff5ff142d747ad833c7aa784113f8558c/tea.go#L39

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	Select: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("enter", "Select current choice"),
	),
	Back: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "Back to previous view"),
	),
	Help: key.NewBinding(
		key.WithKeys("?", "h"),
		key.WithHelp("? / h", "toggle help"),
	),
	Quit: key.NewBinding(
		key.WithKeys("q", "ctrl+c"),
		key.WithHelp("q / ctrl+c", "quit"),
	),
}

Functions

This section is empty.

Types

type Choice

type Choice struct {
	Title       string
	Description string
	Model       tea.Model
}

type KeyMap added in v0.1.2

type KeyMap struct {
	Select key.Binding
	Back   key.Binding
	Help   key.Binding
	Quit   key.Binding
}

func (KeyMap) FullHelp added in v0.1.2

func (k KeyMap) FullHelp() [][]key.Binding

FullHelp returns keybindings for the expanded help view. It's part of the key.Map interface.

func (KeyMap) ShortHelp added in v0.1.2

func (k KeyMap) ShortHelp() []key.Binding

ShortHelp returns keybindings to be shown in the mini help view. It's part of the key.Map interface.

type MenuStyles struct {
	ListTitleStyle lipgloss.Style
	ListItemStyles list.DefaultItemStyles
}

MenuStyles is a struct that holds the styles for the menu This mostly a passthrough for bubble/list component styles.

type Model

type Model struct {
	Choices []Choice

	help.KeyMap
	// contains filtered or unexported fields
}

func New

func New(title string, choices []Choice, selected *Choice) Model

New setups up a new menu model

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) SelectChoice added in v0.1.2

func (m Model) SelectChoice(choice Choice) (Model, tea.Cmd)

SelectChoice pushes the selected choice onto the navigation stack. If the choice is nil, nothing happens.

func (*Model) SetChoices added in v0.1.2

func (m *Model) SetChoices(choices []Choice, selected *Choice)

func (*Model) SetShowTitle added in v0.1.3

func (m *Model) SetShowTitle(display bool)

func (*Model) SetSize

func (m *Model) SetSize(w tea.WindowSizeMsg)

SetSize sets the size of the menu

func (Model) SetStyles added in v0.1.1

func (m Model) SetStyles(s MenuStyles)

SetStyles allows you to customize the styles used by the menu. This is mostly a passthrough to the bubble/list component used by the menu.

func (Model) Update

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

func (Model) View

func (m Model) View() string

View renders the menu. When no choices are present, nothing is rendered.

Jump to

Keyboard shortcuts

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