picker

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrCmd added in v0.16.0

func ErrCmd(err error) tea.Cmd

ErrCmd returns a command that will cause the picker to display an error message and exit.

Types

type CustomAction added in v0.16.0

type CustomAction[T any] struct {
	// Key is the key that the user should press to select this action.
	Key string

	// Description is a short description of what this action does, used in help
	// text.
	//
	// For example, in the help text "o to open.", "to open" is the description.
	Description string

	// Do is the function to call when the user presses the key for this action.
	Do func(selected T) tea.Cmd
}

type ErrMsg added in v0.16.0

type ErrMsg error

ErrMsg is a tea.Msg that indicates an error occurred during the picker's lifecycle.

type Model

type Model[T any] struct {

	// Error is the error that occurred during the picker's lifecycle, if any.
	Error error
	// contains filtered or unexported fields
}

func New

func New[T any](opts Options[T]) Model[T]

New returns a new picker model. The render function is used to render each item in the list.

func (Model[T]) Init

func (m Model[T]) Init() tea.Cmd

func (Model[T]) Picked

func (m Model[T]) Picked() *T

Picked returns the item that was picked by the user, if any. If no item has been picked, this returns nil.

func (Model[T]) Update

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

func (Model[T]) View

func (m Model[T]) View() string

type Options added in v0.16.0

type Options[T any] struct {
	// Items is the list of items to display, from which the user can pick.
	Items []T

	// MessageForZeroItems is the message to display when there are no items to
	// list.
	MessageForZeroItems string

	// ItemRenderFunc is the function to use to render each item in the list. If
	// nil, the item will be rendered via fmt.Sprintf("%v", item).
	ItemRenderFunc func(T) string

	// CustomActions is a list of custom actions that the user can take.
	CustomActions []CustomAction[T]
}

Jump to

Keyboard shortcuts

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