selector

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package selector provides a lightweight cursor component for list-style UI elements. It holds the list of option items (label + key), tracks the selected index, handles up/down key navigation, and renders itself. Disabled items are skipped during navigation but still displayed dimmed.

Index

Constants

View Source
const Unselected = -1

Unselected is the sentinel cursor value meaning no item is highlighted.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Label    string
	Key      string
	Disabled bool
	Style    ItemStyle
}

Item is a single entry in a Selector. Label is the human-readable display string; Key is arbitrary client data. Disabled items are shown dimmed and cannot be navigated to.

type ItemStyle

type ItemStyle int

ItemStyle controls how a selector item is rendered when it is highlighted.

const (
	StyleDefault ItemStyle = iota
	StyleDanger
)

type Selection

type Selection struct {
	Label    string
	Key      string
	Index    int
	Disabled bool
	Style    ItemStyle
}

Selection is the value returned by Selected(). It bundles the chosen item's Label, Key, Disabled flag, and its position Index in the list.

type Selector

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

Selector manages cursor position within a list of Items.

func New

func New(items []Item, cursor int) Selector

New returns a Selector holding items with the given initial cursor. Pass Unselected (-1) if no item should be initially highlighted.

func (Selector) Cursor

func (s Selector) Cursor() int

Cursor returns the current cursor index, or Unselected (-1).

func (Selector) Init

func (s Selector) Init() tea.Cmd

Init satisfies the bubbletea component interface.

func (Selector) Selected

func (s Selector) Selected() (Selection, bool)

Selected returns the selected item and its index. The second return value is false when the cursor is Unselected.

func (Selector) Update

func (s Selector) Update(msg tea.Msg) (Selector, tea.Cmd)

Update processes any tea.Msg. On up/k or down/j the cursor moves, skipping over disabled items. Returns the updated Selector and a nil Cmd.

func (Selector) View

func (s Selector) View() string

View renders the list with a highlighted cursor row and dimmed disabled rows. It returns a string so it can be embedded in a parent model's View output.

Jump to

Keyboard shortcuts

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