v1.1.1
Don't panic!
Panicking is a part of life…and a part of workin’ in Go. This release addresses two edge cases where a panic()
could tank Bubble Tea and break your terminal:
Panics outside of Bubble Tea
If a panic occurs outside of Bubble Tea you can use Program.Kill
to restore the terminal state before exiting:
func main() {
p := tea.NewProgram(model{})
go func() {
time.Sleep(3 * time.Second)
defer p.Kill()
panic("Urgh")
}()
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
}
Panics in Cmds
If a panic occurs in a Cmd
Bubble Tea will now automatically restore the terminal to its natural state before exiting.
type model struct{}
// This command will totally panic.
func pancikyCmd() tea.Msg {
panic("Oh no! Jk.")
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "enter":
// Panic time! But everything will be OK.
return m, pancikyCmd
}
}
return m, nil
}
Happy panicking (if that makes any sense).
Changelog
Fixed!
- 0589921: fix: recover from panics within cmds (@aymanbagabas)
- 6e71f52: fix: restore the terminal on kill (@aymanbagabas)
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or on Discord.