diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2021-03-07 11:30:26 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2021-03-07 11:30:26 +0900 |
commit | e2e8d94b147c164c9c0bf8c2b70e84eb3395657c (patch) | |
tree | b9d626d486d590e108b25a7d4ba9a4699c1bd94b /src | |
parent | 4f9a7f8c879ef625f3bec5946df9e7fe5768f9dd (diff) |
Kill input command on terminate
Fix #2381
Close #2382
Diffstat (limited to 'src')
-rw-r--r-- | src/constants.go | 1 | ||||
-rw-r--r-- | src/core.go | 6 | ||||
-rw-r--r-- | src/terminal.go | 33 |
3 files changed, 24 insertions, 16 deletions
diff --git a/src/constants.go b/src/constants.go index 9842e0bf..96d9821d 100644 --- a/src/constants.go +++ b/src/constants.go @@ -73,6 +73,7 @@ const ( EvtSearchFin EvtHeader EvtReady + EvtQuit ) const ( diff --git a/src/core.go b/src/core.go index a18c3a18..d9a83bd4 100644 --- a/src/core.go +++ b/src/core.go @@ -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) diff --git a/src/terminal.go b/src/terminal.go index 93ba21ba..aac43ceb 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -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() |