diff --git a/src/core.go b/src/core.go index b3af541d..c69ba629 100644 --- a/src/core.go +++ b/src/core.go @@ -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 } diff --git a/src/matcher.go b/src/matcher.go index 73ceebbf..372cdc4f 100644 --- a/src/matcher.go +++ b/src/matcher.go @@ -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) } diff --git a/src/terminal.go b/src/terminal.go index 6879db21..bc02cc47 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -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()