Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run on-quit when terminal closes #1681

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func newApp(ui *ui, nav *nav) *app {
}

func (app *app) quit() {
onQuit(app)

if gOpts.history {
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
Expand Down Expand Up @@ -320,10 +322,6 @@ func (app *app) loop() {
continue
}

if cmd, ok := gOpts.cmds["on-quit"]; ok {
cmd.eval(app, nil)
}

app.quit()

app.nav.previewChan <- ""
Expand Down
6 changes: 6 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ func onSelect(app *app) {
}
}

func onQuit(app *app) {
if cmd, ok := gOpts.cmds["on-quit"]; ok {
cmd.eval(app, nil)
}
}

func splitKeys(s string) (keys []string) {
for i := 0; i < len(s); {
r, w := utf8.DecodeRuneInString(s[i:])
Expand Down