picker

package
v5.78.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package picker provides a reusable interactive list picker built on bubbletea. It presents a list of string items with arrow-key navigation and returns the user's selection.

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("selection cancelled")

ErrCancelled is returned when the user cancels the picker (Esc, q, or Ctrl+C).

View Source
var ErrNoItems = errors.New("no items to select from")

ErrNoItems is returned when the picker is invoked with an empty item list.

View Source
var ErrNotInteractive = errors.New(
	"interactive selection requires a terminal (pass the value as an argument instead)",
)

ErrNotInteractive is returned when stdin is not a terminal.

View Source
var ErrUnexpectedModel = errors.New("unexpected model type from picker")

ErrUnexpectedModel is returned when the bubbletea program returns an unexpected model type.

Functions

func Run

func Run(title string, items []string) (string, error)

Run displays an interactive picker with the given title and items, and returns the user's selected item. Returns ErrCancelled if the user cancels, ErrNoItems if the items slice is empty, or ErrNotInteractive if stdin is not a terminal.

Types

type Model

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

Model is the bubbletea model for the picker. Exported for unit testing of Update/View logic.

func NewModel

func NewModel(title string, items []string) Model

NewModel creates a picker model with the given title and items.

func (Model) Cancelled

func (m Model) Cancelled() bool

Cancelled returns true if the user cancelled the picker.

func (Model) Cursor

func (m Model) Cursor() int

Cursor returns the current cursor position.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (Model) Selected

func (m Model) Selected() string

Selected returns the selected item, or empty string if none selected.

func (Model) Update

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

Update implements tea.Model.

func (Model) View

func (m Model) View() string

View implements tea.Model.

Jump to

Keyboard shortcuts

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