use fresh /dev/tty fd for stdin in input parser
This commit is contained in:
parent
536e34532a
commit
ab75e116e1
@ -49,7 +49,7 @@ func (t *PosixParser) TearDown() error {
|
|||||||
// Read returns byte array.
|
// Read returns byte array.
|
||||||
func (t *PosixParser) Read() ([]byte, error) {
|
func (t *PosixParser) Read() ([]byte, error) {
|
||||||
buf := make([]byte, maxReadBytes)
|
buf := make([]byte, maxReadBytes)
|
||||||
n, err := syscall.Read(syscall.Stdin, buf)
|
n, err := syscall.Read(t.fd, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, err
|
return []byte{}, err
|
||||||
}
|
}
|
||||||
@ -122,7 +122,12 @@ var _ ConsoleParser = &PosixParser{}
|
|||||||
|
|
||||||
// NewStandardInputParser returns ConsoleParser object to read from stdin.
|
// NewStandardInputParser returns ConsoleParser object to read from stdin.
|
||||||
func NewStandardInputParser() *PosixParser {
|
func NewStandardInputParser() *PosixParser {
|
||||||
|
in, err := syscall.Open("/dev/tty", syscall.O_RDONLY, 0)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
return &PosixParser{
|
return &PosixParser{
|
||||||
fd: syscall.Stdin,
|
fd: in,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user