selectinput

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 4 Imported by: 0

README

Select

Bounded single-choice popover with optional typeahead filter.

select preview

Install

glyph add select

This copies select.go (and its test file) into your repo at the path your glyph.json aliases declare. After install, the file is yours: edit it, refactor it, rename it. There is no select library to keep in sync.

Hello, world

package main

import (
	"fmt"

	selectinput "github.com/truffle-dev/glyph/components/select"
	"github.com/truffle-dev/glyph/components/theme"
)

func main() {
	s := selectinput.New(theme.Default).
		WithTitle("Choose a model").
		WithOptions([]selectinput.Option{
			{Label: "Opus 4.7", Hint: "deep thinker"},
			{Label: "Sonnet 4.6", Hint: "fast and balanced"},
			{Label: "Haiku 4.5", Hint: "quick replies"},
		}).
		WithSize(48, 6)
	fmt.Println(s.View())
}

API surface

Package: selectinput

Types

  • Option
  • SelectMsg
  • CancelMsg
  • Select

Functions and methods

  • New
  • WithOptions
  • WithSelected
  • WithSize
  • WithTitle
  • WithPlaceholder
  • WithFilter
  • Cursor
  • Selected
  • Init
  • Update
  • View

Dependencies

  • glyph component theme (installed automatically)
  • github.com/charmbracelet/bubbletea@v1.3.10
  • github.com/charmbracelet/lipgloss@v1.1.0

Notes

Build options with []select.Option{{Label, Hint, Value}}. Up/Down walks; Enter commits with selectinput.SelectMsg{Option, Index}; Esc cancels with selectinput.CancelMsg. Turn on WithFilter(true) for substring typeahead.

See also

License

MIT, same as the rest of glyph.

Documentation

Overview

Package selectinput renders a bounded single-choice popover with an optional substring filter. The picker most agent UIs reach for when there are five to fifty options: a model selector, a workspace switcher, a destination chooser.

The package is named selectinput because select is a Go reserved word. The component owns a cursor and the optional filter; the parent observes SelectMsg on Enter (or Tab) and CancelMsg on Esc.

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 presses Esc.

type Option

type Option struct {
	Label string
	Hint  string
	Value string
}

Option is one row. Value is what comes back on commit; defaults to Label.

type Select

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

Select is a Bubble Tea model for a bounded single-choice picker.

func New

func New(t theme.Theme) Select

New constructs a Select with safe defaults.

func (Select) Cursor

func (s Select) Cursor() int

Cursor returns the index into the visible (filtered) option list.

func (Select) Init

func (s Select) Init() tea.Cmd

Init implements tea.Model.

func (Select) Selected

func (s Select) Selected() (Option, bool)

Selected returns the Option under the cursor, or (zero, false) when empty.

func (Select) Update

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

Update routes key events.

func (Select) View

func (s Select) View() string

View renders the popover: optional title, optional filter input, list body.

func (Select) WithFilter

func (s Select) WithFilter(on bool) Select

WithFilter toggles the typeahead substring filter.

func (Select) WithOptions

func (s Select) WithOptions(opts []Option) Select

WithOptions replaces the option set and resets the cursor.

func (Select) WithPlaceholder

func (s Select) WithPlaceholder(p string) Select

WithPlaceholder sets the empty-filter placeholder. Filter-only.

func (Select) WithSelected

func (s Select) WithSelected(i int) Select

WithSelected sets the initial cursor index, clamped.

func (Select) WithSize

func (s Select) WithSize(w, h int) Select

WithSize sets the rendered width and inner list height.

func (Select) WithTitle

func (s Select) WithTitle(title string) Select

WithTitle sets the title bar above the list.

type SelectMsg

type SelectMsg struct {
	Option Option
	Index  int
}

SelectMsg is emitted when the user commits with Enter or Tab.

Jump to

Keyboard shortcuts

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