prompt

package
v0.35.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoopPrompter

type NoopPrompter struct{}

NoopPrompter always returns defaults. Used for non-TTY, CI, and --yes flag.

func (NoopPrompter) Confirm

func (NoopPrompter) Confirm(_ string, defaultVal bool) (bool, error)

Confirm returns the default value.

func (NoopPrompter) Select added in v0.17.0

func (NoopPrompter) Select(_ string, _ []string, defaultIdx int) (int, error)

Select returns the default index.

func (NoopPrompter) Text

func (NoopPrompter) Text(_, defaultVal string) (string, error)

Text returns the default value.

type Prompter

type Prompter interface {
	// Text prompts for a text value with a default.
	// Displays: "  label: (defaultVal) "
	// Returns defaultVal if user enters empty string.
	Text(label, defaultVal string) (string, error)

	// Confirm prompts for a yes/no with a default.
	// Displays: "  label [Y/n] " or "  label [y/N] "
	// Returns defaultVal if user enters empty string.
	Confirm(label string, defaultVal bool) (bool, error)

	// Select prompts the user to choose from a numbered list.
	// Displays each option with a 1-based index, returns the 0-based selected index.
	// Returns defaultIdx if user enters empty string.
	Select(label string, options []string, defaultIdx int) (int, error)
}

Prompter abstracts interactive input for testability.

func DefaultPrompter

func DefaultPrompter() Prompter

DefaultPrompter returns a TTYPrompter if stdin is a terminal, else NoopPrompter.

type TTYPrompter

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

TTYPrompter reads from a reader (typically os.Stdin).

func New

func New(r *bufio.Reader) *TTYPrompter

New creates a TTYPrompter from a reader.

func (*TTYPrompter) Confirm

func (p *TTYPrompter) Confirm(label string, defaultVal bool) (bool, error)

Confirm prompts for yes/no.

func (*TTYPrompter) Select added in v0.17.0

func (p *TTYPrompter) Select(label string, options []string, defaultIdx int) (int, error)

Select prompts the user to choose from a numbered list.

func (*TTYPrompter) Text

func (p *TTYPrompter) Text(label, defaultVal string) (string, error)

Text prompts for text input.

Jump to

Keyboard shortcuts

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