picker

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package picker provides a filterable single-select list overlay for the tui/app shell — a type-to-filter input over a windowed list, rendered as a centered modal.

The overlay closes itself and emits a ResultMsg; the hosting Content matches on Key to tell pickers apart:

case picker.ResultMsg:
    if field, ok := msg.Key.(configField); ok { ... }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	// Label is the row text; Detail is dimmed, right-aligned extra text.
	// Both are matched by the filter.
	Label  string
	Detail string
	// Value is returned in ResultMsg.
	Value string
}

Item is one selectable row.

type Options

type Options struct {
	// Key is echoed in ResultMsg so apps with several pickers can tell
	// results apart.
	Key   any
	Title string
	// Help is dimmed explanatory text under the title.
	Help  string
	Items []Item
	// InitialIndex preselects an item.
	InitialIndex int
	// Placeholder for the filter input (default "Type to filter").
	Placeholder string
	// Header is an optional column-header line rendered above the rows.
	Header string
	// MaxWidth bounds the modal (default 70).
	MaxWidth int
}

Options configure New.

type Overlay

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

Overlay is a centered filterable list modal.

func New

func New(opts Options) *Overlay

New creates a picker overlay. Push it with Host.PushOverlay.

func (*Overlay) ID

func (o *Overlay) ID() string

ID implements app.Overlay.

func (*Overlay) Init

func (o *Overlay) Init() tea.Cmd

Init implements app.Overlay.

func (*Overlay) Items

func (o *Overlay) Items() []Item

Items returns all items the picker was created with.

func (*Overlay) Key

func (o *Overlay) Key() any

Key returns the identifier the picker was created with.

func (*Overlay) Len

func (o *Overlay) Len() int

Len returns the number of items matching the current filter.

func (*Overlay) Update

func (o *Overlay) Update(msg tea.Msg) (app.Overlay, tea.Cmd)

Update implements app.Overlay.

func (*Overlay) View

func (o *Overlay) View(width, height int) string

View implements app.Overlay.

type ResultMsg

type ResultMsg struct {
	// Key identifies which picker resolved (Options.Key, may be nil).
	Key       any
	Cancelled bool
	Value     string
	// Index is the chosen item's index in Options.Items.
	Index int
}

ResultMsg is emitted when the picker closes.

Jump to

Keyboard shortcuts

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