Skip to content

Commit

Permalink
fix(bubbletea): stop window change watching loop after tea.Program st…
Browse files Browse the repository at this point in the history
…opped (#145)
  • Loading branch information
LindsayZhou committed Jun 8, 2023
1 parent 78e6bbd commit e6e4f48
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bubbletea/tea.go
Expand Up @@ -2,6 +2,8 @@
package bubbletea

import (
"context"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
Expand Down Expand Up @@ -69,10 +71,11 @@ func MiddlewareWithProgramHandler(bth ProgramHandler, cp termenv.Profile) wish.M
p := bth(s)
if p != nil {
_, windowChanges, _ := s.Pty()
ctx, cancel := context.WithCancel(s.Context())
go func() {
for {
select {
case <-s.Context().Done():
case <-ctx.Done():
if p != nil {
p.Quit()
return
Expand All @@ -91,6 +94,7 @@ func MiddlewareWithProgramHandler(bth ProgramHandler, cp termenv.Profile) wish.M
// and restore the terminal to its original state in case of a
// tui crash
p.Kill()
cancel()
}
sh(s)
}
Expand Down

0 comments on commit e6e4f48

Please sign in to comment.