Skip to content

Commit

Permalink
fix: better diff
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Jan 5, 2024
1 parent 83cc777 commit 60e8254
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions bubbletea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,38 @@ func Middleware(bth Handler) wish.Middleware {
opts = append(opts, hopts...)

p := tea.NewProgram(m, opts...)
ctx, cancel := context.WithCancel(s.Context())
go func() {
for {
select {
case <-ctx.Done():
if p != nil {
p.Quit()
return
}
case w := <-windowChanges:
if p != nil {
p.Send(tea.WindowSizeMsg{Width: w.Width, Height: w.Height})
if p != nil {
ctx, cancel := context.WithCancel(s.Context())
go func() {
for {
select {
case <-ctx.Done():
if p != nil {
p.Quit()
return
}
case w := <-windowChanges:
if p != nil {
p.Send(tea.WindowSizeMsg{Width: w.Width, Height: w.Height})
}
}
}
}()
if _, err := p.Run(); err != nil {
log.Error("app exit with error", "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
p.Kill()
cancel()
if err := tty.Close(); err != nil {
log.Error("could not close pty", "error", err)
return
}
}()
if _, err := p.Run(); err != nil {
log.Error("app exit with error", "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
p.Kill()
cancel()
if err := tty.Close(); err != nil {
log.Error("could not close pty", "error", err)
return
}

sh(s)
sh(s)
}
}
}
}
Expand Down

0 comments on commit 60e8254

Please sign in to comment.