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 d0af93e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 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
}
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 d0af93e

Please sign in to comment.