summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2021-11-18 18:56:04 +0100
committerHubert Hirtz <hubert@hirtz.pm>2021-11-18 19:06:21 +0100
commit06fbb04b4c0628c1befbe824be5ba333e2f3afec (patch)
tree055a2e4ddca200d045b720726a8a7ff1657330d9 /app.go
parentOK GitHub: update README.MD (diff)
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).
Diffstat (limited to 'app.go')
-rw-r--r--app.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/app.go b/app.go
index c44dc05..db5c776 100644
--- a/app.go
+++ b/app.go
@@ -192,7 +192,9 @@ func (app *App) eventLoop() {
if ev.content == nil {
return
}
- app.handleUIEvent(ev.content)
+ if !app.handleUIEvent(ev.content) {
+ return
+ }
} else {
app.handleIRCEvent(ev.src, ev.content)
}
@@ -359,7 +361,7 @@ func (app *App) uiLoop() {
}
}
-func (app *App) handleUIEvent(ev interface{}) {
+func (app *App) handleUIEvent(ev interface{}) bool {
switch ev := ev.(type) {
case *tcell.EventResize:
app.win.Resize()
@@ -369,11 +371,15 @@ func (app *App) handleUIEvent(ev interface{}) {
app.handleMouseEvent(ev)
case *tcell.EventKey:
app.handleKeyEvent(ev)
+ case *tcell.EventError:
+ // happens when the terminal is closing: in which case, exit
+ return false
case statusLine:
app.addStatusLine(ev.netID, ev.line)
default:
panic("unreachable")
}
+ return true
}
func (app *App) handleMouseEvent(ev *tcell.EventMouse) {