Documentation
¶
Overview ¶
Package prompt asks one-shot questions: selects, confirms, inputs.
The engine is deliberately plain: print the bullet question, read one line, parse the answer. No cursor tracking, no re-renders, no second render pass — so output cannot duplicate on any terminal, legacy consoles included. Numbered lists replace arrow-key menus; masked passwords use the OS no-echo read. Ctrl+C cancels through ctx.
Every prompt takes a Preset (the already-parsed flag value). A valid preset returns immediately without touching the terminal, so flags always win. Without a preset the terminal must be interactive; otherwise the prompt fails naming the required flag instead of hanging on a pipe.
Render pausing is the caller's job: pause live drawing before prompting and resume after, or the menu and the tree garble each other. See app.Context PauseDrawing and ResumeDrawing.
Index ¶
- func Confirm(ctx context.Context, io IO, opts ConfirmOptions) (bool, error)
- func Input(ctx context.Context, io IO, opts InputOptions) (string, error)
- func MultiSelect(ctx context.Context, io IO, opts MultiSelectOptions) ([]string, error)
- func Password(ctx context.Context, io IO, opts PasswordOptions) (string, error)
- func Select(ctx context.Context, io IO, opts SelectOptions) (string, error)
- type ConfirmOptions
- type FileReader
- type FileWriter
- type IO
- type InputOptions
- type MultiSelectOptions
- type PasswordOptions
- type SelectOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MultiSelect ¶
MultiSelect picks options by comma-separated numbers.
Types ¶
type ConfirmOptions ¶
type ConfirmOptions struct {
Message string
Default bool
// Preset returns unprompted when non-nil.
Preset *bool
Flag string
}
ConfirmOptions tunes a Confirm call.
type FileReader ¶ added in v1.1.1
FileReader is a readable file descriptor: consoles, pipes, files.
type FileWriter ¶ added in v1.1.1
FileWriter is a writable file descriptor.
type IO ¶
type IO struct {
In FileReader
Out FileWriter
Err io.Writer
// NoColor strips prompt styling (dumb terminals, --no-color).
// The bullet glyph itself always renders.
NoColor bool
}
IO carries stdio for prompts. Use StdIO in real apps; tests pass pipes.
type InputOptions ¶
type InputOptions struct {
Message string
Default string
// Preset returns unprompted when non-nil (empty string is valid input).
Preset *string
Flag string
}
InputOptions tunes an Input call.
type MultiSelectOptions ¶
type MultiSelectOptions struct {
Message string
Options []string
// Default preselects (subset of Options).
Default []string
// Preset returns unprompted when non-nil (validated subset).
Preset []string
Flag string
}
MultiSelectOptions tunes a MultiSelect call.
type PasswordOptions ¶
type PasswordOptions struct {
Message string
// Preset returns unprompted when non-nil.
Preset *string
Flag string
}
PasswordOptions tunes a Password call.
type SelectOptions ¶
type SelectOptions struct {
// Message is the question, e.g. "Target environment?".
Message string
// Options are the choices in order.
Options []string
// Default preselects when prompting (must be one of Options).
Default string
// Preset is the parsed flag value: validated and returned unprompted.
Preset string
// Flag names the flag for errors, e.g. "--env".
Flag string
}
SelectOptions tunes a Select call.