Kill input command on terminate
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix #2381 Close #2382
authored by Junegunn Choi · committed by Junegunn Choi · parent 4f9a7f8 · Browse files · 3 files·+24 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+24 added−16 removed
- other:+24 added−16 removed
Provenance
- Commit
e2e8d94- Tree
b9d626d- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
4f9a7f8
3 files changed+24 added−16 removed
modified:src/constants.go+1 added
71 unmodified lines72 EvtSearchProgress73 EvtSearchFin74 EvtHeader75 EvtReady76+ EvtQuit77 )78 79 const (80 exitCancel = -15 unmodified linesmodified:src/core.go+5 added-1 removed
252 unmodified lines253 delete(*events, EvtReadNew)254 }255 for evt, value := range *events {256 switch evt {257-257+ case EvtQuit:258+ if reading {259+ reader.terminate()260+ }261+ os.Exit(value.(int))262 case EvtReadNew, EvtReadFin:263 if evt == EvtReadFin && nextCommand != nil {264 restart(*nextCommand)265 nextCommand = nil85 unmodified linesmodified:src/terminal.go+18 added-15 removed
1824 unmodified lines1825 select {1826 case t.killChan <- code:1827 default:1828 if code != exitCancel {1829- os.Exit(code)1829+ t.eventBox.Set(EvtQuit, code)1830 }1831 }1832 }1833 1834 func (t *Terminal) cancelPreview() {1835 t.killPreview(exitCancel)1836 }1837 1838+func (t *Terminal) exit(getCode func() int) {1839+ t.tui.Close()1840+ code := getCode()1841+ if code <= exitNoMatch && t.history != nil {1842+ t.history.append(string(t.input))1843+ }1844+ // prof.Stop()1845+ t.killPreview(code)1846+}1847+1848 // Loop is called to start Terminal I/O1849 func (t *Terminal) Loop() {1850 // prof := profile.Start(profile.ProfilePath("/tmp/"))1851 <-t.startChan167 unmodified lines2019 t.reqBox.Set(reqPreviewDelayed, version)2020 case code := <-t.killChan:2021 if code != exitCancel {2022 util.KillCommand(cmd)2013- os.Exit(code)2023+ t.eventBox.Set(EvtQuit, code)2024 } else {2025 timer := time.NewTimer(previewCancelWait)2026 select {2027 case <-timer.C:28 unmodified lines2056 }2057 }()2058 }2059 2050- exit := func(getCode func() int) {2051- t.tui.Close()2052- code := getCode()2053- if code <= exitNoMatch && t.history != nil {2054- t.history.append(string(t.input))2055- }2056- // prof.Stop()2057- t.killPreview(code)2058- }2059-2060 refreshPreview := func(command string) {2061 if len(command) > 0 && t.isPreviewEnabled() {2062 _, list := t.buildPlusList(command, false)2063 t.cancelPreview()43 unmodified lines2107 t.redraw()2108 case reqRedraw:2109 t.redraw()2110 case reqClose:2111- exit(func() int {2111+ t.exit(func() int {2112 if t.output() {2113 return exitOk2114 }2115 return exitNoMatch2116 })2117+ return2118 case reqPreviewDisplay:2119 result := value.(previewResult)2120 if t.previewer.version != result.version {2121 t.previewer.version = result.version12 unmodified lines2134 case reqPreviewDelayed:2135 t.previewer.version = value.(int64)2136 t.printPreviewDelayed()2137 case reqPrintQuery:2137- exit(func() int {2138+ t.exit(func() int {2139 t.printer(string(t.input))2140 return exitOk2141 })2142+ return2143 case reqQuit:2142- exit(func() int { return exitInterrupt })2144+ t.exit(func() int { return exitInterrupt })2145+ return2146 }2147 }2148 t.refresh()2149 t.mutex.Unlock()578 unmodified lines