picker

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package picker is a generic, minimal list picker. It supports two modes: a flat list of items, and a list grouped by an optional provider-style header per group. The cursor walks items only; headers are non-selectable. With a non-empty filter, the picker keeps every group whose name or any model name matches the (case-insensitive) needle.

The picker is the shared building block for /model (one provider or many) and /agents (single flat list). The ProviderModelGroup metadata carried by the config catalog (Active, Selectable, DisabledReason) is intentionally not rendered here: Selectable gates the catalog before it reaches the picker, Active renders in the top bar, and DisabledReason is a config-time error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelMsg

type CancelMsg struct{}

CancelMsg is emitted when the user aborts with Esc.

type Group

type Group struct {
	Provider string
	Models   []string
}

Group is one header-and-items block in the picker. An empty Provider renders the items without a header, so a single Group with Provider "" is a flat list.

type Model

type Model struct {
	Theme theme.Theme
	Tier  theme.Tier
	// contains filtered or unexported fields
}

Model is a single-component picker. Construct it with New for a flat list, or with NewGroups for a list of groups. NewGroups with one Group whose Provider is "" renders a flat list.

func New

func New(t theme.Theme, tier theme.Tier, items []string) Model

New returns a picker over a flat list of items with the cursor on the first row.

func NewGroups

func NewGroups(t theme.Theme, tier theme.Tier, groups []Group) Model

NewGroups returns a picker over grouped items. Empty groups (Models: nil) are dropped. A group with an empty Provider renders without a header, so a single anonymous group acts as a flat list. The cursor starts on the first model item.

func (*Model) ClearFilter

func (m *Model) ClearFilter()

ClearFilter drops the active filter and resets the cursor to the first model item. Owners that dismiss the list (or hand focus away from it) use it so a stale filter cannot resurface as an unexplained short list.

func (Model) CursorRow

func (m Model) CursorRow() int

CursorRow is the cursor's row within the visible list, so a caller that windows the list into a pane can keep the highlighted row on screen.

func (Model) Filter

func (m Model) Filter() string

Filter exposes the active filter: a caller that rebinds and holds a cursor by row index needs to know whether that row is even visible.

func (*Model) MoveTo

func (m *Model) MoveTo(index int)

MoveTo places the cursor on the row at index, clamped to the visible list. Callers that rebuild a picker (a live-updating list) use it to hold the selection steady across the rebuild.

func (*Model) Rebind

func (m *Model) Rebind(items []string)

Rebind swaps the item set, keeping the filter and clamping the cursor to a model item. A live-updating list (the files panel) refreshes its rows through this, so an in-progress filter survives a rebuild that picker.New would reset.

func (*Model) RebindGroups

func (m *Model) RebindGroups(groups []Group)

RebindGroups swaps the grouped item set, keeping the filter and clamping the cursor to a model item.

func (Model) Selected

func (m Model) Selected() (string, bool)

Selected returns the currently highlighted item and whether the (visible) list has a model under the cursor. Headers are not selectable, so the bool is false whenever the cursor sits on a header.

func (Model) Update

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

func (Model) View

func (m Model) View() string

View returns the full list of items (unwindowed).

func (Model) ViewWindow

func (m Model) ViewWindow(maxRows int) string

ViewWindow returns a window of items sized to fit within maxRows lines, ensuring the currently selected item (cursor) is always visible. If maxRows <= 0, all items are rendered.

type SelectMsg

type SelectMsg struct{ Item string }

SelectMsg is emitted when the user confirms a selection with Enter.

Jump to

Keyboard shortcuts

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