2022-03-08 10:45:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"bytes"
|
2023-02-01 23:28:36 +00:00
|
|
|
"fmt"
|
2022-03-08 10:45:56 +00:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func askSecret(prompt string) []byte {
|
|
|
|
stdinTTY.EchoOff()
|
|
|
|
|
|
|
|
var (
|
|
|
|
in io.Reader = stdin
|
|
|
|
out io.Writer = stdout
|
|
|
|
)
|
|
|
|
|
|
|
|
if stdin == nil {
|
|
|
|
in = os.Stdin
|
|
|
|
out = os.Stdout
|
|
|
|
}
|
|
|
|
|
|
|
|
out.Write([]byte(prompt + ": "))
|
|
|
|
|
|
|
|
if stdin != nil {
|
|
|
|
stdout.HideInput()
|
|
|
|
}
|
|
|
|
|
|
|
|
s, err := bufio.NewReader(in).ReadBytes('\n')
|
|
|
|
|
|
|
|
if stdin != nil {
|
|
|
|
stdout.ShowInput()
|
|
|
|
}
|
|
|
|
|
|
|
|
stdinTTY.Restore()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fatalf("failed to read from stdin: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-02-01 23:28:36 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
2022-03-08 10:45:56 +00:00
|
|
|
s = bytes.TrimRight(s, "\r\n")
|
|
|
|
return s
|
|
|
|
}
|