blob: 59ad81c352ad3b5269881c5a4969a3fc6a4c3969 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package keyring
import (
"fmt"
"os"
"golang.org/x/term"
)
// PromptFunc is a function used to prompt the user for a password.
type PromptFunc func(string) (string, error)
func TerminalPrompt(prompt string) (string, error) {
fmt.Printf("%s: ", prompt)
b, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return "", err
}
fmt.Println()
return string(b), nil
}
func FixedStringPrompt(value string) PromptFunc {
return func(_ string) (string, error) {
return value, nil
}
}
|