jesseduffield / jesseduffield/lazygit
Panics can sometimes cause terminal issues
- Dominant language
- Go
- Stars
- 82.4k
- Forks
- 3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 19
Description
**Describe the bug**
When lazygit panics from inside a goroutine, termbox is never asked to return the terminal back to its original state, meaning weird things can happen like printing characters when you click or scroll your mouse
**To Reproduce**
Create a goroutine and panic from within it, then see how your terminal responds to mouse clicks. I tested by panicking from escape.go in the gocui fork which itself was run inside a task from tasks.go
**Expected behavior**
terminal returns to normal state
**Screenshots**

**Desktop (please complete the following information):**
- OS: OSX
- Lazygit Version commit d2d88fe6
**Additional context**
There's no way to recover from every goroutine, we might need some recovery boilerplate inside every goroutine, of which there are at least 25. Maybe we need a standardised way to run a goroutine i.e.
```
go safeGoroutine(func() {
// do stuff
})
func safeGoroutine(f func()) {
defer func() {
if r := recover(); r != nil {
termbox.Close()
panic(r)
}
}()
f()
}
```
Luckily termbox is defined globally so we can do this from anywhere. I might actually chuck a 'good first issue' label on this one
Contributor guide
Assessment
This issue has not been assessed yet.