From e6e4f48969480442b080234a9283932df8f98c69 Mon Sep 17 00:00:00 2001 From: Lindsay Zhou Date: Thu, 8 Jun 2023 14:48:05 +0000 Subject: [PATCH] fix(bubbletea): stop window change watching loop after tea.Program stopped (#145) --- bubbletea/tea.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bubbletea/tea.go b/bubbletea/tea.go index ff17737..a6a1bb5 100644 --- a/bubbletea/tea.go +++ b/bubbletea/tea.go @@ -2,6 +2,8 @@ package bubbletea import ( + "context" + tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/log" @@ -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 @@ -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) }