Kill input command on terminate

Fix #2381
Close #2382
pull/2379/head
Junegunn Choi 3 years ago
parent 4f9a7f8c87
commit e2e8d94b14
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -73,6 +73,7 @@ const (
EvtSearchFin
EvtHeader
EvtReady
EvtQuit
)
const (

@ -254,7 +254,11 @@ func Run(opts *Options, version string, revision string) {
}
for evt, value := range *events {
switch evt {
case EvtQuit:
if reading {
reader.terminate()
}
os.Exit(value.(int))
case EvtReadNew, EvtReadFin:
if evt == EvtReadFin && nextCommand != nil {
restart(*nextCommand)

@ -1826,7 +1826,7 @@ func (t *Terminal) killPreview(code int) {
case t.killChan <- code:
default:
if code != exitCancel {
os.Exit(code)
t.eventBox.Set(EvtQuit, code)
}
}
}
@ -1835,6 +1835,16 @@ func (t *Terminal) cancelPreview() {
t.killPreview(exitCancel)
}
func (t *Terminal) exit(getCode func() int) {
t.tui.Close()
code := getCode()
if code <= exitNoMatch && t.history != nil {
t.history.append(string(t.input))
}
// prof.Stop()
t.killPreview(code)
}
// Loop is called to start Terminal I/O
func (t *Terminal) Loop() {
// prof := profile.Start(profile.ProfilePath("/tmp/"))
@ -2010,7 +2020,7 @@ func (t *Terminal) Loop() {
case code := <-t.killChan:
if code != exitCancel {
util.KillCommand(cmd)
os.Exit(code)
t.eventBox.Set(EvtQuit, code)
} else {
timer := time.NewTimer(previewCancelWait)
select {
@ -2047,16 +2057,6 @@ func (t *Terminal) Loop() {
}()
}
exit := func(getCode func() int) {
t.tui.Close()
code := getCode()
if code <= exitNoMatch && t.history != nil {
t.history.append(string(t.input))
}
// prof.Stop()
t.killPreview(code)
}
refreshPreview := func(command string) {
if len(command) > 0 && t.isPreviewEnabled() {
_, list := t.buildPlusList(command, false)
@ -2108,12 +2108,13 @@ func (t *Terminal) Loop() {
case reqRedraw:
t.redraw()
case reqClose:
exit(func() int {
t.exit(func() int {
if t.output() {
return exitOk
}
return exitNoMatch
})
return
case reqPreviewDisplay:
result := value.(previewResult)
if t.previewer.version != result.version {
@ -2134,12 +2135,14 @@ func (t *Terminal) Loop() {
t.previewer.version = value.(int64)
t.printPreviewDelayed()
case reqPrintQuery:
exit(func() int {
t.exit(func() int {
t.printer(string(t.input))
return exitOk
})
return
case reqQuit:
exit(func() int { return exitInterrupt })
t.exit(func() int { return exitInterrupt })
return
}
}
t.refresh()

Loading…
Cancel
Save