Terminate when terminal failed to boot

pull/3769/head
Junegunn Choi 4 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)) return unsafe.Slice(unsafe.StringData(data), len(data))
} }
type quitSignal struct {
code int
err error
}
// Run starts fzf // Run starts fzf
func Run(opts *Options) (int, error) { func Run(opts *Options) (int, error) {
if err := postProcessOptions(opts); err != nil { if err := postProcessOptions(opts); err != nil {
@ -287,7 +292,9 @@ func Run(opts *Options) (int, error) {
if reading { if reading {
reader.terminate() reader.terminate()
} }
exitCode = value.(int) quitSignal := value.(quitSignal)
exitCode = quitSignal.code
err = quitSignal.err
stop = true stop = true
return return
case EvtReadNew, EvtReadFin: case EvtReadNew, EvtReadFin:
@ -414,5 +421,5 @@ func Run(opts *Options) (int, error) {
time.Sleep(dur) time.Sleep(dur)
} }
} }
return exitCode, nil return exitCode, err
} }

@ -35,7 +35,6 @@ type Matcher struct {
const ( const (
reqRetry util.EventType = iota reqRetry util.EventType = iota
reqReset reqReset
reqStop
) )
// NewMatcher returns a new Matcher // NewMatcher returns a new Matcher
@ -64,7 +63,7 @@ func (m *Matcher) Loop() {
stop := false stop := false
m.reqBox.Wait(func(events *util.Events) { m.reqBox.Wait(func(events *util.Events) {
for t, val := range *events { for t, val := range *events {
if t == reqStop { if t == reqQuit {
stop = true stop = true
return return
} }
@ -247,5 +246,5 @@ func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final
} }
func (m *Matcher) Stop() { 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 { if err := t.initFunc(); err != nil {
t.mutex.Unlock() t.mutex.Unlock()
cancel() cancel()
t.eventBox.Set(EvtQuit, quitSignal{ExitError, err})
return err return err
} }
t.termSize = t.tui.Size() 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.running.Set(false)
t.killPreview() t.killPreview()
cancel() cancel()

Loading…
Cancel
Save