fix: handle when stdin is in nonblocking mode (closes #136)

ctrl-delete
TorchedSammy 2022-04-08 10:46:25 -04:00
parent 393fe3962f
commit c342f4f6f5
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 9 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"regexp" "regexp"
"syscall"
) )
var rxMultiline = regexp.MustCompile(`[\r\n]+`) var rxMultiline = regexp.MustCompile(`[\r\n]+`)
@ -77,6 +78,14 @@ func (rl *Instance) Readline() (string, error) {
var err error var err error
i, err = os.Stdin.Read(b) i, err = os.Stdin.Read(b)
if err != nil { if err != nil {
// i shouldnt really check the error like this but i dont know what
// the actual thing is so
if err.Error() == "read /dev/stdin: resource temporarily unavailable" {
err = syscall.SetNonblock(syscall.Stdin, false)
if err == nil {
continue
}
}
return "", err return "", err
} }
} }