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 28 29 30 31 32
|
// +build linux darwin freebsd
package input
import (
"fmt"
"os"
"golang.org/x/crypto/ssh/terminal"
)
// LineSep is the separator for windows or unix systems
const LineSep = "\n"
// rawRead reads file with raw mode (without prompting to terminal).
func (i *UI) rawRead(f *os.File) (string, error) {
// MakeRaw put the terminal connected to the given file descriptor
// into raw mode
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 i.rawReadline(f)
}
|