picker

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package picker provides a tiny searchable terminal picker. The stateful filtering/navigation logic is independent of terminal setup and is used by configure tests without a model call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Select

func Select(ctx context.Context, in io.Reader, out io.Writer, options []Option, view View) (Option, Action, error)

Select reads one raw-key wizard screen without requiring a paid provider. A lone Escape is recognized after a short sequence window and therefore does not wait for a second byte forever on pipes or terminals.

func UnknownAvailabilityWarning

func UnknownAvailabilityWarning(model runner.ModelInfo) string

Types

type Action

type Action int
const (
	ActionSelected Action = iota
	ActionBack
	ActionCancel
)

type Key

type Key int
const (
	KeyRune Key = iota
	KeyUp
	KeyDown
	KeyEnter
	KeyEscape
	KeyBackspace
)

type Option

type Option struct {
	ID          string
	Label       string
	Description string
	Meta        string
}

func EffortOptions

func EffortOptions(model runner.ModelInfo) []Option

func ModelOptions

func ModelOptions(models []runner.ModelInfo) []Option

func Pick

func Pick(ctx context.Context, in io.Reader, out io.Writer, options []Option) (Option, bool, error)

Pick is the small standalone searchable picker API. Escape and Ctrl+C both report cancellation; multi-screen callers should use Select to distinguish back navigation from cancellation.

func SpeedOptions

func SpeedOptions(model runner.ModelInfo) []Option

type Screen

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

Screen owns the alternate terminal buffer used by the configure wizard. Leaving it restores the caller's original terminal contents.

func NewScreen

func NewScreen(out io.Writer) *Screen

func (*Screen) Enter

func (s *Screen) Enter()

func (*Screen) Leave

func (s *Screen) Leave()

func (*Screen) ShowStatus

func (s *Screen) ShowStatus(title, message string)

ShowStatus replaces the alternate-screen contents while a wizard performs bounded work between interactive screens. This avoids presenting a blank terminal during provider authentication probes or model discovery.

type State

type State struct {
	Options []Option
	Query   string
	Cursor  int
}

func New

func New(options []Option) *State

func (*State) Backspace

func (s *State) Backspace()

func (*State) Filtered

func (s *State) Filtered() []Option

func (*State) Handle

func (s *State) Handle(key Key, r rune) (selected *Option, cancelled bool)

func (*State) Input

func (s *State) Input(r rune)

func (*State) Move

func (s *State) Move(delta int)

func (*State) Selected

func (s *State) Selected() (Option, bool)

type View

type View struct {
	Title      string
	Subtitle   string
	InitialID  string
	Search     bool
	CanBack    bool
	FullScreen bool
}

View controls one wizard screen. FullScreen clears the alternate buffer before the first frame; CanBack makes Escape return to the previous screen.

Jump to

Keyboard shortcuts

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