Skip to content

Commit

Permalink
fix: goroutine leak (#79)
Browse files Browse the repository at this point in the history
* fix: goroutine leak

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: why even an error channel

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Oct 26, 2022
1 parent 61ca856 commit 9a56088
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions bubbletea/tea.go
Expand Up @@ -67,7 +67,6 @@ func MiddlewareWithProgramHandler(bth ProgramHandler, cp termenv.Profile) wish.M
return func(sh ssh.Handler) ssh.Handler {
lipgloss.SetColorProfile(cp)
return func(s ssh.Session) {
errc := make(chan error, 1)
p := bth(s)
if p != nil {
_, windowChanges, _ := s.Pty()
Expand All @@ -77,19 +76,18 @@ func MiddlewareWithProgramHandler(bth ProgramHandler, cp termenv.Profile) wish.M
case <-s.Context().Done():
if p != nil {
p.Quit()
return
}
case w := <-windowChanges:
if p != nil {
p.Send(tea.WindowSizeMsg{Width: w.Width, Height: w.Height})
}
case err := <-errc:
if err != nil {
log.Print(err)
}
}
}
}()
errc <- p.Start()
if err := p.Start(); err != nil {
log.Print("app exit with error:", err)
}
// p.Kill() will force kill the program if it's still running,
// and restore the terminal to its original state in case of a
// tui crash
Expand Down

0 comments on commit 9a56088

Please sign in to comment.