10 // Ask the user to enter a password with input hidden. prompt is a string to
11 // display before the user's input. Returns the provided password, or an error
12 // if the command failed.
13 func Ask(prompt string) (password string, err error) {
14 return FAsk(os.Stdout, prompt)
17 // FAsk is the same as Ask, except it is possible to specify the file to write
18 // the prompt to. If 'nil' is passed as the writer, no prompt will be written.
19 func FAsk(wr io.Writer, prompt string) (password string, err error) {
20 if wr != nil && prompt != "" {
21 fmt.Fprint(wr, prompt) // Display the prompt.
23 password, err = getPassword()
25 // Carriage return after the user input.
32 func readline() (value string, err error) {
37 // read one byte at a time so we don't accidentally read extra bytes
38 n, err = os.Stdin.Read(b)
39 if err != nil && err != io.EOF {
42 if n == 0 || b[0] == '\n' {
45 valb = append(valb, b[0])
48 return strings.TrimSuffix(string(valb), "\r"), nil