Documentation
¶
Overview ¶
Package prompt asks a person at a terminal for a line of text, one choice from a list, or yes or no.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = errors.New("cancelled")
ErrCancelled reports that the person pressed Ctrl-C or closed the input instead of answering.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option struct {
// Label is the choice as the person reads it.
Label string
// Hint is a short note shown dimmed after the label, or empty.
Hint string
}
Option is one choice a Select offers.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal asks its questions on a terminal that understands ANSI cursor codes. Each question holds the terminal in raw mode until it is answered, so Ctrl-C reaches the question as a key and cancels it.
func NewTerminal ¶
NewTerminal returns a Terminal that reads answers from in and shows its questions on out, in color when color is true.
func (*Terminal) Confirm ¶
Confirm asks a yes or no question and returns the answer, or fallback when the person presses Enter.
func (*Terminal) Select ¶
Select asks for one of options, starting on the one at selected, and returns the chosen option's index. The arrow keys, j and k move, a digit jumps to that option, and Enter chooses.