fix password input lowercasing characters.

fixes https://github.com/fiatjaf/nak/issues/28
This commit is contained in:
fiatjaf 2024-08-06 11:05:07 -03:00
parent 3d78e91f62
commit d226cd6ce4

View File

@ -261,22 +261,18 @@ func askPassword(msg string, shouldAskAgain func(answer string) bool) (string, e
EnableMask: true,
MaskRune: '*',
}
return _ask(config, msg, "", shouldAskAgain)
}
func _ask(config *readline.Config, msg string, defaultValue string, shouldAskAgain func(answer string) bool) (string, error) {
rl, err := readline.NewEx(config)
if err != nil {
return "", err
}
rl.WriteStdin([]byte(defaultValue))
for {
answer, err := rl.Readline()
if err != nil {
return "", err
}
answer = strings.TrimSpace(strings.ToLower(answer))
answer = strings.TrimSpace(answer)
if shouldAskAgain != nil && shouldAskAgain(answer) {
continue
}