prompt

package
v1.115.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package prompt implements small terminal prompts (text input, yes/no confirmation, single- and multi-choice selection, and a filterable, generic picker) on top of github.com/charmbracelet/bubbletea.

Index

Constants

This section is empty.

Variables

View Source
var ErrAborted = errors.New("prompt aborted")

ErrAborted is returned when the user cancels a prompt, e.g. via Ctrl+C or Esc. It is not used by PickOne, which signals cancellation through its own ok return value instead; see PickOne's doc comment.

Functions

func Ask

func Ask(ctx context.Context, cfg Config) (string, error)

Ask displays a single-field terminal prompt and returns the entered value. It returns ErrAborted if the user cancels the prompt, or if ctx is canceled while the prompt is running.

func Confirm

func Confirm(ctx context.Context, cfg ConfirmConfig) (bool, error)

Confirm displays a yes/no terminal prompt and returns the user's choice. Pressing Enter without typing y/n returns cfg.Default. It returns ErrAborted if the user cancels the prompt, or if ctx is canceled while the prompt is running.

func MultiSelect

func MultiSelect(ctx context.Context, cfg MultiSelectConfig) ([]string, error)

MultiSelect displays a multiple-choice terminal prompt and returns the chosen options, in the order they were listed in cfg.Options. It returns ErrAborted if the user cancels the prompt, if ctx is canceled while the prompt is running, or if no options are provided.

func PickOne

func PickOne[T any](ctx context.Context, title string, options []Option[T]) (value T, ok bool, err error)

PickOne shows options in an interactive, filterable list, under the given title. Type "/" to filter the list, use the arrow keys to move, and press enter to pick the highlighted option. Disabled options cannot be picked.

PickOne returns the Value of the picked option. ok is false if the user canceled instead of picking an option (via Esc or Ctrl+C); this is not reported as an error. Canceling ctx also cancels the picker; PickOne then returns a non-nil error.

func Required

func Required(s string) error

Required is a Validate function that rejects empty (or whitespace-only) input.

func Select

func Select(ctx context.Context, cfg SelectConfig) (string, error)

Select displays a single-choice terminal prompt and returns the chosen option. It returns ErrAborted if the user cancels the prompt, if ctx is canceled while the prompt is running, or if no options are provided.

Types

type Config

type Config struct {
	// Message is the question shown to the user.
	Message string

	// Help, if set, is displayed underneath the message.
	Help string

	// Default, if set, pre-fills the input. The user can edit or clear
	// it before submitting.
	Default string

	// EchoMode controls how typed input is displayed, e.g.
	// textinput.EchoPassword to mask the input. Defaults to
	// textinput.EchoNormal.
	EchoMode textinput.EchoMode

	// Validate, if set, must pass before the input is accepted on submit.
	// The prompt will keep re-displaying the error and accepting input
	// until it does.
	Validate func(string) error
}

Config describes a single-field text prompt.

type ConfirmConfig

type ConfirmConfig struct {
	// Message is the question shown to the user.
	Message string

	// Help, if set, is displayed underneath the message.
	Help string

	// Default is the choice highlighted initially, and the one used when
	// the user presses Enter without typing y/n explicitly.
	Default bool
}

ConfirmConfig describes a yes/no confirmation prompt.

type MultiSelectConfig

type MultiSelectConfig struct {
	// Message is the question shown to the user.
	Message string

	// Help, if set, is displayed underneath the message.
	Help string

	// Options are the choices presented to the user. Toggle an option
	// with Space, move with the up/down (or j/k) arrow keys, and confirm
	// the current set of selections with Enter.
	Options []string
}

MultiSelectConfig describes a multiple-choice prompt.

type Option

type Option[T any] struct {
	// Label is the option's main text.
	Label string

	// Description is a second line of text under Label.
	Description string

	// Disabled options show in the list, but the user cannot pick them.
	// Description, if set, explains why.
	Disabled bool

	// Value is the value PickOne returns for this option.
	Value T
}

Option is one choice in a PickOne list.

type SelectConfig

type SelectConfig struct {
	// Message is the question shown to the user.
	Message string

	// Help, if set, is displayed underneath the message.
	Help string

	// Options are the choices presented to the user, selectable with the
	// up/down (or j/k) arrow keys.
	Options []string
}

SelectConfig describes a single-choice prompt.

Jump to

Keyboard shortcuts

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