Terminate when terminal failed to boot

pull/3769/head
Junegunn Choi 2 weeks ago
parent 38b4faa5dc
commit ef7a9e5c13
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -26,6 +26,11 @@ func sbytes(data string) []byte {
return unsafe.Slice(unsafe.StringData(data), len(data))
}
type quitSignal struct {
code int
err error
}
// Run starts fzf
func Run(opts *Options) (int, error) {
if err := postProcessOptions(opts); err != nil {
@ -287,7 +292,9 @@ func Run(opts *Options) (int, error) {
if reading {
reader.terminate()
}
exitCode = value.(int)
quitSignal := value.(quitSignal)
exitCode = quitSignal.code
err = quitSignal.err
stop = true
return
case EvtReadNew, EvtReadFin:
@ -414,5 +421,5 @@ func Run(opts *Options) (int, error) {
time.Sleep(dur)
}
}
return exitCode, nil
return exitCode, err
}

@ -35,7 +35,6 @@ type Matcher struct {
const (
reqRetry util.EventType = iota
reqReset
reqStop
)
// NewMatcher returns a new Matcher
@ -64,7 +63,7 @@ func (m *Matcher) Loop() {
stop := false
m.reqBox.Wait(func(events *util.Events) {
for t, val := range *events {
if t == reqStop {
if t == reqQuit {
stop = true
return
}
@ -247,5 +246,5 @@ func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final
}
func (m *Matcher) Stop() {
m.reqBox.Set(reqStop, MatchRequest{})
m.reqBox.Set(reqQuit, nil)
}

@ -2963,6 +2963,7 @@ func (t *Terminal) Loop() error {
if err := t.initFunc(); err != nil {
t.mutex.Unlock()
cancel()
t.eventBox.Set(EvtQuit, quitSignal{ExitError, err})
return err
}
t.termSize = t.tui.Size()
@ -3299,7 +3300,7 @@ func (t *Terminal) Loop() error {
})
}
t.eventBox.Set(EvtQuit, code)
t.eventBox.Set(EvtQuit, quitSignal{code, nil})
t.running.Set(false)
t.killPreview()
cancel()

Loading…
Cancel
Save