boot v2 progress: disks, ssh, success...
This commit is contained in:
43
ask-secret.go
Normal file
43
ask-secret.go
Normal file
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"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)
|
||||
}
|
||||
|
||||
s = bytes.TrimRight(s, "\r\n")
|
||||
return s
|
||||
}
|
Reference in New Issue
Block a user