mirror of https://github.com/chzyer/readline.git
fixed crash if stdin is not a tty (pipe)
This commit is contained in:
parent
07485bbd8f
commit
21acaf90fd
|
@ -84,6 +84,13 @@ func (o *Operation) ioloop() {
|
||||||
keepInSearchMode := false
|
keepInSearchMode := false
|
||||||
keepInCompleteMode := false
|
keepInCompleteMode := false
|
||||||
r := o.t.ReadRune()
|
r := o.t.ReadRune()
|
||||||
|
if r == 0 { // io.EOF
|
||||||
|
o.buf.Clean()
|
||||||
|
select {
|
||||||
|
case o.errchan <- io.EOF:
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
isUpdateHistory := true
|
isUpdateHistory := true
|
||||||
|
|
||||||
if o.IsInCompleteSelectMode() {
|
if o.IsInCompleteSelectMode() {
|
||||||
|
|
|
@ -67,8 +67,13 @@ func (t *Terminal) Readline() *Operation {
|
||||||
return NewOperation(t, t.cfg)
|
return NewOperation(t, t.cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return rune(0) if meet EOF
|
||||||
func (t *Terminal) ReadRune() rune {
|
func (t *Terminal) ReadRune() rune {
|
||||||
return <-t.outchan
|
ch, ok := <-t.outchan
|
||||||
|
if !ok {
|
||||||
|
return rune(0)
|
||||||
|
}
|
||||||
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) IsReading() bool {
|
func (t *Terminal) IsReading() bool {
|
||||||
|
@ -136,6 +141,7 @@ func (t *Terminal) ioloop() {
|
||||||
t.outchan <- r
|
t.outchan <- r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(t.outchan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) Bell() {
|
func (t *Terminal) Bell() {
|
||||||
|
|
1
utils.go
1
utils.go
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
StdinFd = int(uintptr(syscall.Stdin))
|
StdinFd = int(uintptr(syscall.Stdin))
|
||||||
|
StdoutFd = int(uintptr(syscall.Stdout))
|
||||||
isWindows = false
|
isWindows = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ type winsize struct {
|
||||||
func getWidth() int {
|
func getWidth() int {
|
||||||
ws := &winsize{}
|
ws := &winsize{}
|
||||||
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
|
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
|
||||||
uintptr(StdinFd),
|
uintptr(StdoutFd),
|
||||||
uintptr(syscall.TIOCGWINSZ),
|
uintptr(syscall.TIOCGWINSZ),
|
||||||
uintptr(unsafe.Pointer(ws)))
|
uintptr(unsafe.Pointer(ws)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue