commit 06fbb04
delthas
·
2021-11-18 17:56:04 +0000 UTC
parent 2f73a20
Handle tcell error events by closing This is namely useful when the terminal is closing: these events are sent, and we should close when that happens (instead of panicking).
1 files changed,
+8,
-2
M
app.go
M
app.go
+8,
-2
1@@ -192,7 +192,9 @@ func (app *App) eventLoop() {
2 if ev.content == nil {
3 return
4 }
5- app.handleUIEvent(ev.content)
6+ if !app.handleUIEvent(ev.content) {
7+ return
8+ }
9 } else {
10 app.handleIRCEvent(ev.src, ev.content)
11 }
12@@ -359,7 +361,7 @@ func (app *App) uiLoop() {
13 }
14 }
15
16-func (app *App) handleUIEvent(ev interface{}) {
17+func (app *App) handleUIEvent(ev interface{}) bool {
18 switch ev := ev.(type) {
19 case *tcell.EventResize:
20 app.win.Resize()
21@@ -369,11 +371,15 @@ func (app *App) handleUIEvent(ev interface{}) {
22 app.handleMouseEvent(ev)
23 case *tcell.EventKey:
24 app.handleKeyEvent(ev)
25+ case *tcell.EventError:
26+ // happens when the terminal is closing: in which case, exit
27+ return false
28 case statusLine:
29 app.addStatusLine(ev.netID, ev.line)
30 default:
31 panic("unreachable")
32 }
33+ return true
34 }
35
36 func (app *App) handleMouseEvent(ev *tcell.EventMouse) {