From ab75e116e1546b91152d8a4789b7a8a7b06da7ef Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Sun, 12 Aug 2018 21:36:13 +0000 Subject: [PATCH] use fresh /dev/tty fd for stdin in input parser --- input_posix.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/input_posix.go b/input_posix.go index 46ecb51..a9a2db6 100644 --- a/input_posix.go +++ b/input_posix.go @@ -49,7 +49,7 @@ func (t *PosixParser) TearDown() error { // Read returns byte array. func (t *PosixParser) Read() ([]byte, error) { buf := make([]byte, maxReadBytes) - n, err := syscall.Read(syscall.Stdin, buf) + n, err := syscall.Read(t.fd, buf) if err != nil { return []byte{}, err } @@ -122,7 +122,12 @@ var _ ConsoleParser = &PosixParser{} // NewStandardInputParser returns ConsoleParser object to read from stdin. func NewStandardInputParser() *PosixParser { + in, err := syscall.Open("/dev/tty", syscall.O_RDONLY, 0) + if err != nil { + panic(err) + } + return &PosixParser{ - fd: syscall.Stdin, + fd: in, } }