Skip to content

Commit

Permalink
Merge branch 'abrander-dont-panic'
Browse files Browse the repository at this point in the history
  • Loading branch information
Verseth committed Jul 1, 2023
2 parents a43e8c1 + e701ec0 commit d9c8c58
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions input_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package prompt

import (
"os"
"syscall"

"github.com/c-bata/go-prompt/internal/term"
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d9c8c58

Please sign in to comment.