Skip to content
Myr

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

3 files+24 added−16 removed

modified:src/constants.go+1 added
71 unmodified lines
72 EvtSearchProgress73 EvtSearchFin74 EvtHeader75 EvtReady76 EvtQuit77)7879const (80 exitCancel = -1
5 unmodified lines
modified:src/core.go+5 added-1 removed
252 unmodified lines
253 delete(*events, EvtReadNew)254 }255 for evt, value := range *events {256 switch evt {257257 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 = nil
85 unmodified lines
modified:src/terminal.go+18 added-15 removed
1824 unmodified lines
1825 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}18331834func (t *Terminal) cancelPreview() {1835 t.killPreview(exitCancel)1836}18371838func (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}18471848// Loop is called to start Terminal I/O1849func (t *Terminal) Loop() {1850 // prof := profile.Start(profile.ProfilePath("/tmp/"))1851 <-t.startChan
167 unmodified lines
2019 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 lines
2056 }2057 }()2058 }20592050 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 }20592060 refreshPreview := func(command string) {2061 if len(command) > 0 && t.isPreviewEnabled() {2062 _, list := t.buildPlusList(command, false)2063 t.cancelPreview()
43 unmodified lines
2107 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.version
12 unmodified lines
2134 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