prompt

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 7 Imported by: 0 modules, 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 the user questions on an interactive terminal.

Prompts are written to stderr, never stdout: a command that asks a question must still be safe to pipe. Everything here is driven through an io.Reader so that the specs can feed it a buffer instead of a terminal.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInteractive = errors.New("no interactive terminal")

ErrNotInteractive is returned when a prompt is needed but there is no terminal to ask on — a CI job, or a command whose stdin is a pipe. Commands turn it into "pass --flag instead", which is the only useful thing to say.

Functions

func IsTerminal

func IsTerminal(v any) bool

IsTerminal reports whether v is an interactive terminal. It accepts anything carrying a file descriptor, so it answers for os.Stdin and os.Stdout alike; a bytes.Buffer has none, which is exactly why a spec's streams are never mistaken for a terminal.

func ReadAll

func ReadAll(r io.Reader) (string, error)

ReadAll reads a secret piped on stdin, for --password-stdin. It trims a single trailing newline — `echo secret | fft ...` appends one and the user did not mean it to be part of the password — but nothing else, because leading and trailing spaces can be genuine.

Types

type Confirmer added in v0.8.0

type Confirmer func(question string) (bool, error)

Confirmer answers a yes/no question somewhere other than on the terminal. fft's interactive UI is one: a command it runs has no terminal of its own, and the question is asked in a dialog. An error is never a yes.

type Option

type Option func(*Prompter)

Option configures a Prompter.

func WithConfirmer added in v0.8.0

func WithConfirmer(c Confirmer) Option

WithConfirmer sends every Prompter.Confirm to c. The other prompts still read in, and still need a terminal there: a Confirmer answers yes or no, and nothing else.

func WithInteractive

func WithInteractive(v bool) Option

WithInteractive overrides whether in is treated as a terminal.

Nothing in fft passes it: production reads the answer off the file descriptor. The specs pass it, because that is the only way to drive the question a destructive command asks.

type Prompter

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

Prompter reads answers from in and writes questions to out.

func New

func New(in io.Reader, out io.Writer, opts ...Option) *Prompter

New returns a Prompter reading from in and writing prompts to out. out should be stderr.

func (*Prompter) CanConfirm added in v0.8.0

func (p *Prompter) CanConfirm() bool

CanConfirm reports whether Prompter.Confirm reaches someone who can answer: a terminal on in, or a Confirmer.

func (*Prompter) Confirm

func (p *Prompter) Confirm(label string) (bool, error)

Confirm asks a yes/no question. Anything other than "y" or "yes" is a no — destructive commands should never proceed on an ambiguous answer.

func (*Prompter) Interactive

func (p *Prompter) Interactive() bool

Interactive reports whether in is a terminal a user could answer on.

func (*Prompter) Line

func (p *Prompter) Line(label, def string) (string, error)

Line asks for a value, offering def as the default. An empty answer takes the default.

func (*Prompter) Password

func (p *Prompter) Password(label string) (string, error)

Password asks for a secret. On a terminal the input is masked; otherwise it is read as a plain line, which is what lets the specs drive it.

func (*Prompter) Required

func (p *Prompter) Required(label string) (string, error)

Required asks for a value and keeps asking until it gets a non-empty one.

func (*Prompter) Validated added in v0.4.0

func (p *Prompter) Validated(label string, validate func(string) error) (string, error)

Validated asks for a non-empty value and keeps asking until validate accepts it, printing the rejection message as the hint — the same shape as Required, with a caller-supplied acceptance rule on top.

Jump to

Keyboard shortcuts

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