Skip to content

Commit

Permalink
Run on-quit when terminal closes (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelim-work committed Apr 7, 2024
1 parent 63815aa commit ce12116
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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 @@ -580,6 +580,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

0 comments on commit ce12116

Please sign in to comment.