pick

package
v0.0.0-...-8079059 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pick

func Pick(label string, horizontal bool, idx int, items ...string) (int, error)

Pick asks to pick an item and return its index or an error. Use errors.Is(ui.Canceled) or errors.Is(ui.Quit) to determine if the selection was canceled or aborting of the program was requested.

func Showcase

func Showcase()

Showcase demonstrates all features of the Model component by creating various list models and running interactive examples in the terminal.

Types

type Model

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

Model represents a selectable list component.

func New

func New(items []string) *Model

New creates and returns a new Model with the given items.

func (*Model) Canceled

func (m *Model) Canceled() bool

Canceled returns the canceled flag.

func (*Model) Init

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

Init initializes the Model and returns a nil command.

func (*Model) Quit

func (m *Model) Quit() bool

Quit returns the quit flag.

func (*Model) SelectedIdx

func (m *Model) SelectedIdx() int

SelectedIdx returns the index of the selected item.

func (*Model) SelectedItem

func (m *Model) SelectedItem() string

SelectedItem returns the selected item, or an empty string if no selection was performed.

func (*Model) Update

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

Update handles user input and updates the list state by processing key messages and updating the selected index accordingly.

func (*Model) View

func (m *Model) View() string

View renders the list as a string, displaying the label and items with their respective styles.

func (*Model) WithCancel

func (m *Model) WithCancel(cancelable bool) *Model

WithCancel sets the cancelable flag and returns a new Model with the updated flag.

func (*Model) WithHorizontal

func (m *Model) WithHorizontal(horizontal bool) *Model

WithHorizontal sets whether the items should be displayed horizontally and returns a new Model with the updated horizontal setting.

func (*Model) WithLabel

func (m *Model) WithLabel(label string) *Model

WithLabel sets the label of the Model and returns a new Model with the updated label.

func (*Model) WithLabelColor

func (m *Model) WithLabelColor(color lipgloss.Color) *Model

WithLabelColor sets the color of the label and returns a new Model with the updated label color.

func (*Model) WithLabelStyle

func (m *Model) WithLabelStyle(style lipgloss.Style) *Model

WithLabelStyle sets the style of the label and returns a new Model with the updated label style.

func (*Model) WithNormalFormat

func (m *Model) WithNormalFormat(format string) *Model

WithNormalFormat sets the format string for normal (unselected) items and returns a new Model with the updated normal format.

func (*Model) WithNormalItemColor

func (m *Model) WithNormalItemColor(color lipgloss.Color) *Model

WithNormalItemColor sets the color of the normal (unselected) items and returns a new Model with the updated normal item color.

func (*Model) WithNormalItemStyle

func (m *Model) WithNormalItemStyle(style lipgloss.Style) *Model

WithNormalItemStyle sets the style of the normal (unselected) items and returns a new Model with the updated normal item style.

func (*Model) WithQuit

func (m *Model) WithQuit(quitable bool) *Model

WithQuit sets the quitable flag and returns a new Model with the updated flag.

func (*Model) WithSelectedFormat

func (m *Model) WithSelectedFormat(format string) *Model

WithSelectedFormat sets the format string for the selected item and returns a new Model with the updated selected format.

func (*Model) WithSelectedIndex

func (m *Model) WithSelectedIndex(i int) *Model

WithSelectedIndex sets the index of the initially selected item and returns a new Model with the updated selected index.

func (*Model) WithSelectedItemColor

func (m *Model) WithSelectedItemColor(color lipgloss.Color) *Model

WithSelectedItemColor sets the color of the selected item and returns a new Model with the updated selected item color.

func (*Model) WithSelectedItemStyle

func (m *Model) WithSelectedItemStyle(style lipgloss.Style) *Model

WithSelectedItemStyle sets the style of the selected item and returns a new Model with the updated selected item style.

Jump to

Keyboard shortcuts

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