forked from mirror/readline
fix Ctrl+C in search mode do not send EOF
This commit is contained in:
parent
a904b314b8
commit
af66dc48f7
|
@ -114,7 +114,9 @@ func (o *Operation) ioloop() {
|
||||||
}
|
}
|
||||||
case CharInterrupt:
|
case CharInterrupt:
|
||||||
if o.IsSearchMode() {
|
if o.IsSearchMode() {
|
||||||
o.ExitSearchMode(false)
|
o.t.KickRead()
|
||||||
|
o.ExitSearchMode(true)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
o.buf.MoveToLineEnd()
|
o.buf.MoveToLineEnd()
|
||||||
o.buf.Refresh()
|
o.buf.Refresh()
|
||||||
|
|
|
@ -45,6 +45,9 @@ func (i *Instance) ReadSlice() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Instance) Close() error {
|
func (i *Instance) Close() error {
|
||||||
|
if err := i.t.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
i.o.Close()
|
i.o.Close()
|
||||||
return i.t.Close()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
20
terminal.go
20
terminal.go
|
@ -19,7 +19,7 @@ type Terminal struct {
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
kickChan chan struct{}
|
kickChan chan struct{}
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
isReading bool
|
isReading int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTerminal(cfg *Config) (*Terminal, error) {
|
func NewTerminal(cfg *Config) (*Terminal, error) {
|
||||||
|
@ -60,7 +60,7 @@ func (t *Terminal) ReadRune() rune {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) IsReading() bool {
|
func (t *Terminal) IsReading() bool {
|
||||||
return t.isReading
|
return atomic.LoadInt64(&t.isReading) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) KickRead() {
|
func (t *Terminal) KickRead() {
|
||||||
|
@ -82,10 +82,10 @@ func (t *Terminal) ioloop() {
|
||||||
buf := bufio.NewReader(os.Stdin)
|
buf := bufio.NewReader(os.Stdin)
|
||||||
for {
|
for {
|
||||||
if !expectNextChar {
|
if !expectNextChar {
|
||||||
t.isReading = false
|
atomic.StoreInt64(&t.isReading, 0)
|
||||||
select {
|
select {
|
||||||
case <-t.kickChan:
|
case <-t.kickChan:
|
||||||
t.isReading = true
|
atomic.StoreInt64(&t.isReading, 1)
|
||||||
case <-t.stopChan:
|
case <-t.stopChan:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -109,21 +109,17 @@ func (t *Terminal) ioloop() {
|
||||||
r = escapeExKey(r)
|
r = escapeExKey(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expectNextChar = true
|
||||||
switch r {
|
switch r {
|
||||||
case CharInterrupt:
|
|
||||||
t.outchan <- r
|
|
||||||
goto exit
|
|
||||||
case CharEsc:
|
case CharEsc:
|
||||||
isEscape = true
|
isEscape = true
|
||||||
expectNextChar = true
|
case CharInterrupt, CharEnter, CharCtrlJ:
|
||||||
case CharEnter, CharCtrlJ:
|
expectNextChar = false
|
||||||
t.outchan <- r
|
fallthrough
|
||||||
default:
|
default:
|
||||||
expectNextChar = true
|
|
||||||
t.outchan <- r
|
t.outchan <- r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) Close() error {
|
func (t *Terminal) Close() error {
|
||||||
|
|
Loading…
Reference in New Issue