Skip to content

Commit

Permalink
Merge pull request c-bata#89 from bcicen/reopen-stdin
Browse files Browse the repository at this point in the history
use fresh /dev/tty fd for stdin in input parser
  • Loading branch information
c-bata committed Aug 26, 2018
2 parents aa7dc8b + ab75e11 commit 846777c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions input_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}
}

0 comments on commit 846777c

Please sign in to comment.