prompt

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package prompt asks one-shot questions: selects, confirms, inputs.

Every prompt takes a Preset (the already-parsed flag value). A valid preset returns immediately without touching the terminal, so flags always win. Without a preset the terminal must be interactive; otherwise the prompt fails naming the required flag instead of hanging on a pipe.

Render pausing is the caller's job: stop or pause live drawing before prompting and resume after, or the menu and the tree garble each other. Ctrl+C surfaces as terminal.InterruptErr; use IsInterrupt to map it to exit code 130 in main.

The interactive survey path is intentionally thin: unit tests stub the single askOne call site and assert the exact survey structs built. Survey's own suite plus the demo matrix cover real TTYs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Confirm

func Confirm(io IO, opts ConfirmOptions) (bool, error)

Confirm asks yes/no.

func Input

func Input(io IO, opts InputOptions) (string, error)

Input reads one line, echoing input.

func IsInterrupt

func IsInterrupt(err error) bool

IsInterrupt reports Ctrl+C during a prompt (map to exit code 130).

func MultiSelect

func MultiSelect(io IO, opts MultiSelectOptions) ([]string, error)

MultiSelect picks zero or more options with space and enter.

func Password

func Password(io IO, opts PasswordOptions) (string, error)

Password reads one line masked with stars.

func Select

func Select(io IO, opts SelectOptions) (string, error)

Select picks one option with arrow keys and enter.

Types

type ConfirmOptions

type ConfirmOptions struct {
	Message string
	Default bool
	// Preset returns unprompted when non-nil.
	Preset *bool
	Flag   string
}

ConfirmOptions tunes a Confirm call.

type IO

type IO struct {
	In  terminal.FileReader
	Out terminal.FileWriter
	Err io.Writer
	// NoColor strips prompt icon colors (dumb terminals, --no-color).
	// The bullet glyph itself always renders.
	NoColor bool
}

IO carries stdio for prompts. Use StdIO in real apps; tests pass pipes.

func StdIO

func StdIO() IO

StdIO wires the process standard streams for prompts.

type InputOptions

type InputOptions struct {
	Message string
	Default string
	// Preset returns unprompted when non-nil (empty string is valid input).
	Preset *string
	Flag   string
}

InputOptions tunes an Input call.

type MultiSelectOptions

type MultiSelectOptions struct {
	Message string
	Options []string
	// Default preselects (subset of Options).
	Default []string
	// Preset returns unprompted when non-nil (validated subset).
	Preset []string
	Flag   string
}

MultiSelectOptions tunes a MultiSelect call.

type PasswordOptions

type PasswordOptions struct {
	Message string
	// Preset returns unprompted when non-nil.
	Preset *string
	Flag   string
}

PasswordOptions tunes a Password call.

type SelectOptions

type SelectOptions struct {
	// Message is the question, e.g. "Target environment?".
	Message string
	// Options are the choices in order.
	Options []string
	// Default preselects when prompting (must be one of Options).
	Default string
	// Preset is the parsed flag value: validated and returned unprompted.
	Preset string
	// Flag names the flag for errors, e.g. "--env".
	Flag string
}

SelectOptions tunes a Select call.

Jump to

Keyboard shortcuts

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