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 ¶
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 ¶
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.
Types ¶
type Option ¶
type Option func(*Prompter)
Option configures a Prompter.
func WithInteractive ¶
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 (*Prompter) Confirm ¶
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 ¶
Interactive reports whether in is a terminal a user could answer on.
func (*Prompter) Line ¶
Line asks for a value, offering def as the default. An empty answer takes the default.