Skip to content

Commit

Permalink
Terminate when terminal failed to boot
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed May 6, 2024
1 parent 38b4faa commit ef7a9e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -414,5 +421,5 @@ func Run(opts *Options) (int, error) {
time.Sleep(dur)
}
}
return exitCode, nil
return exitCode, err
}
5 changes: 2 additions & 3 deletions src/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Matcher struct {
const (
reqRetry util.EventType = iota
reqReset
reqStop
)

// NewMatcher returns a new Matcher
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ef7a9e5

Please sign in to comment.