Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type Prompt struct {
// Validate is an optional function that fill be used against the entered value in the prompt to validate it.
Validate ValidateFunc

// Lazy validation on <Enter> only.
LazyValidation bool

// Mask is an optional rune that sets which character to display instead of the entered characters. This
// allows hiding private information like passwords.
Mask rune
Expand Down Expand Up @@ -157,10 +160,17 @@ func (p *Prompt) Run() (string, error) {

listen := func(input []rune, pos int, key rune) ([]rune, int, bool) {
_, _, keepOn := cur.Listen(input, pos, key)
err := validFn(cur.Get())
var prompt []byte
var (
err error
prompt []byte
)

if err != nil {
if p.LazyValidation == false {
err = validFn(cur.Get())
}


if err != nil || p.LazyValidation {
prompt = render(p.Templates.invalid, p.Label)
} else {
prompt = render(p.Templates.valid, p.Label)
Expand Down