2016-03-16 19:47:55 +00:00
|
|
|
// +build linux darwin freebsd netbsd openbsd
|
2015-03-04 08:31:35 +00:00
|
|
|
|
|
|
|
package password
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
)
|
|
|
|
|
|
|
|
func read(f *os.File) (string, error) {
|
|
|
|
fd := int(f.Fd())
|
|
|
|
if !terminal.IsTerminal(fd) {
|
|
|
|
return "", fmt.Errorf("File descriptor %d is not a terminal", fd)
|
|
|
|
}
|
|
|
|
|
|
|
|
oldState, err := terminal.MakeRaw(fd)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer terminal.Restore(fd, oldState)
|
|
|
|
|
|
|
|
return readline(f)
|
|
|
|
}
|