Documentation
¶
Overview ¶
Package console asks a person to confirm on the console device, never on stdin or stdout, so piping `yes` or capturing output cannot answer it.
Index ¶
- Constants
- func ChoiceText(ch approval.Choice) string
- func ColorCapable(f *os.File) bool
- func Flush(dev io.ReadWriteCloser)
- func IsTerminal(f *os.File) bool
- func NewCode(r io.Reader) (string, error)
- func Open() (io.ReadWriteCloser, error)
- func Usable(stdin, stderr *os.File) bool
- func Width(f *os.File) int
- type Challenger
Constants ¶
const ( DefaultTimeout = 5 * time.Minute DefaultAttempts = 3 )
const Alphabet = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"
Alphabet has no look-alike characters (no 0 O 1 I L).
const ChoicePrompt = "Press Enter for "
ChoicePrompt starts the question a Choice asks when more than one option can be picked.
Variables ¶
This section is empty.
Functions ¶
func ChoiceText ¶
ChoiceText is how ch shows: its title, then one line per option, the default marked ❯ and an unavailable one with its reason.
func ColorCapable ¶
ColorCapable reports whether f is a terminal, which takes ANSI escape codes.
func Flush ¶
func Flush(dev io.ReadWriteCloser)
Flush discards what was typed on the console device before a question, so an Enter pressed earlier can't answer it. Only a real console device is flushed; anything else is left alone.
func IsTerminal ¶
IsTerminal reports whether f is a terminal (a real console handle on Windows).
func NewCode ¶
NewCode returns a random code. Bytes of 248 and above are rejected so each of the 31 characters is equally likely.
Types ¶
type Challenger ¶
type Challenger struct {
Open func() (io.ReadWriteCloser, error)
Rand io.Reader
Timeout time.Duration
Attempts int
After func(time.Duration) <-chan time.Time
}
Challenger implements approval.Approver on the console device.
func (*Challenger) Confirm ¶
func (c *Challenger) Confirm(ctx context.Context, summary string) error
Confirm shows summary and a one-time code on the console, and returns nil only when the person types the code back.
func (*Challenger) ConfirmChoosing ¶
func (c *Challenger) ConfirmChoosing(ctx context.Context, summary string, ch approval.Choice) (int, error)
ConfirmChoosing is Confirm with ch asked between the summary and the code (R2): Enter picks ch.Default, an option's key, name or number picks it, and an unavailable option asks again. With one option left, ch is shown and nothing is asked. It returns the option chosen. A default that isn't an option that can be picked is refused before the console opens.