24 lines
295 B
Go
24 lines
295 B
Go
|
package prompt
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"syscall"
|
||
|
|
||
|
"golang.org/x/term"
|
||
|
)
|
||
|
|
||
|
func PasswordPrompt(label string) string {
|
||
|
var s string
|
||
|
for {
|
||
|
fmt.Fprint(os.Stderr, label+" ")
|
||
|
b, _ := term.ReadPassword(int(syscall.Stdin))
|
||
|
s = string(b)
|
||
|
if s != "" {
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
fmt.Println()
|
||
|
return s
|
||
|
}
|