picker

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package picker is the CLI's interactive list chooser: a numbered table on stderr, a prompt on stdin. Typing a number picks, typing text filters the list (case-insensitive substring), an empty answer takes the default. No alternate screen, no raw mode — it works in any terminal and is scriptable by piping answers, which is also how the test suite drives it.

Index

Constants

This section is empty.

Variables

View Source
var ErrBack = errors.New("back")

ErrBack is returned on Esc (with an empty filter): go one screen back. Screens without a parent treat it like ErrCancelled.

View Source
var ErrCancelled = errors.New("cancelled")

ErrCancelled is returned on Ctrl-C: leave the whole program.

View Source
var ErrTab = errors.New("tab")

ErrTab is returned when Tab is pressed on a single-select screen — the application-wide "switch to the downloads screen" gesture. Multi-select keeps Tab for marking.

View Source
var ExtraHint func() string

ExtraHint, when set, contributes an application status fragment to every picker's hint line (e.g. "tab: downloads (2 active)").

Functions

func Pick

func Pick(title string, items []Item, def int) (int, error)

Pick lets the person choose exactly one item and returns its index: the arrow-key list on a real terminal, the numbered prompt otherwise (piped answers, WEBTOR_PLAIN_PICKER=1, dumb terminals). def is the default index (-1 for none).

func PickLive added in v1.7.0

func PickLive(title string, refresh func() []Item) (int, error)

PickLive is Pick for data that changes underneath: refresh is called before every frame (and every ~500ms of idle time when the platform supports polling reads), so progress-style screens stay current without keystrokes. Enter returns the selected index into the LAST refreshed slice, Esc returns ErrBack, Ctrl-C ErrCancelled. Plain environments fall back to a one-shot numbered prompt over a snapshot.

func PickMulti

func PickMulti(title string, items []Item) ([]int, error)

PickMulti lets the person choose several items: Tab marks in the arrow-key list; the numbered fallback understands "3", "1,4", "2-5", "all".

func ReadLine added in v1.4.0

func ReadLine(prompt string) (string, error)

ReadLine prints prompt on stderr and reads one trimmed line from stdin, sharing the program-wide Scanner so buffered piped answers are not lost.

func Show added in v1.6.2

func Show(title string, lines []string) error

Show renders a read-only text screen in the picker's style: the lines are width-fitted, any key returns (Ctrl-C cancels), and the frame erases itself. Piped/plain environments print the lines and wait for Enter.

Types

type Item

type Item struct {
	Label  string
	Detail string
}

Item is one selectable row.

Jump to

Keyboard shortcuts

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