diff --git a/input_posix.go b/input_posix.go index 1eae228e..6a7e8187 100644 --- a/input_posix.go +++ b/input_posix.go @@ -4,6 +4,7 @@ package prompt import ( + "os" "syscall" "github.com/c-bata/go-prompt/internal/term" @@ -20,7 +21,9 @@ type PosixParser struct { // Setup should be called before starting input func (t *PosixParser) Setup() error { in, err := syscall.Open("/dev/tty", syscall.O_RDONLY, 0) - if err != nil { + if os.IsNotExist(err) { + in = syscall.Stdin + } else if err != nil { panic(err) } t.fd = in @@ -59,7 +62,12 @@ func (t *PosixParser) Read() ([]byte, error) { func (t *PosixParser) GetWinSize() *WinSize { ws, err := unix.IoctlGetWinsize(t.fd, unix.TIOCGWINSZ) if err != nil { - panic(err) + // If this errors, we simply return the default window size as + // it's our best guess. + return &WinSize{ + Row: 25, + Col: 80, + } } return &WinSize{ Row: ws.Row,