2024-11-22 15:29:25 +00:00
|
|
|
package prompt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/term"
|
|
|
|
)
|
|
|
|
|
|
|
|
func PasswordPrompt(label string) string {
|
2024-12-16 18:22:58 +00:00
|
|
|
var str string
|
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
for {
|
|
|
|
fmt.Fprint(os.Stderr, label+" ")
|
2024-12-16 18:22:58 +00:00
|
|
|
|
|
|
|
b, _ := term.ReadPassword(syscall.Stdin)
|
|
|
|
|
|
|
|
str = string(b)
|
|
|
|
if str != "" {
|
2024-11-22 15:29:25 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2024-12-16 18:22:58 +00:00
|
|
|
|
2024-11-22 15:29:25 +00:00
|
|
|
fmt.Println()
|
2024-12-16 18:22:58 +00:00
|
|
|
|
|
|
|
return str
|
2024-11-22 15:29:25 +00:00
|
|
|
}
|