prompt

package
v0.75.6 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package prompt provides reusable terminal UI widgets built on charm.land/bubbletea/v2 and charm.land/bubbles/v2.

Every public constructor checks whether stdin is an interactive terminal and whether stderr or stdout can render terminal output before starting a bubbletea program. If either side is unavailable, the constructor returns (zero, ErrNotInteractive) immediately so callers in CI / pipe mode can detect the condition and fall back to non-interactive paths without any risk of hanging.

Index

Constants

This section is empty.

Variables

View Source
var ErrInterrupted = errors.New("prompt: interrupted")

ErrInterrupted is returned when the user aborts an interactive prompt.

View Source
var ErrNotInteractive = errors.New("prompt: stdin is not a terminal")

ErrNotInteractive is returned by all constructors when stdin is not a terminal.

Functions

func CanPrompt added in v0.75.6

func CanPrompt() bool

CanPrompt reports whether prompts can safely read input and render output.

func Confirm

func Confirm(question string, def bool) (bool, error)

Confirm asks a yes/no question. def is the default answer shown in the prompt (used when the user presses Enter without typing y/n).

Returns (false, ErrNotInteractive) when stdin is not a terminal.

func Input

func Input(label string, masked bool) (string, error)

Input prompts the user for a single-line text value. When masked is true the input is displayed as asterisks (suitable for passwords/tokens).

Returns ("", ErrNotInteractive) when stdin is not a terminal.

func InputWithSuggestions added in v0.75.3

func InputWithSuggestions(label string, masked bool, suggestions []string) (string, error)

InputWithSuggestions prompts the user for a single-line text value and shows completion suggestions when suggestions is non-empty. Tab accepts the current suggestion using the underlying bubbles textinput behavior.

func MultiSelect

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

MultiSelect presents an interactive multi-choice list. Returns the indices of all selected items. Items can be pre-selected via Item.Preselected.

Returns (nil, ErrNotInteractive) when stdin is not a terminal.

func Select

func Select(title string, opts []string) (int, error)

Select presents an interactive single-choice list to the user and returns the index of the chosen item.

Returns (0, ErrNotInteractive) when stdin is not a terminal.

Types

type Item

type Item struct {
	Label       string
	Preselected bool
}

Item is a selectable entry for MultiSelect.

Jump to

Keyboard shortcuts

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