diff --git a/app.go b/app.go index 4bd9b3ed..562d32af 100644 --- a/app.go +++ b/app.go @@ -95,6 +95,14 @@ func (app *app) quit() { } } +// requestQuit signals the main loop to quit and never blocks when a request is already pending. +func (app *app) requestQuit() { + select { + case app.quitChan <- struct{}{}: + default: + } +} + func (app *app) readFile(path string) { log.Printf("reading file: %s", path) diff --git a/eval.go b/eval.go index d3990cc3..59b16796 100644 --- a/eval.go +++ b/eval.go @@ -1046,7 +1046,7 @@ func (e *callExpr) eval(app *app, _ []string) { switch e.name { case "quit": - app.quitChan <- struct{}{} + app.requestQuit() case "up": if app.nav.up(e.count) { app.ui.loadFile(app, true) @@ -1111,7 +1111,7 @@ func (e *callExpr) eval(app *app, _ []string) { } else { if gSelectionPath != "" || gPrintSelection { app.selectionOut, _ = app.nav.currFileOrSelections() - app.quitChan <- struct{}{} + app.requestQuit() return }