From 06fbb04b4c0628c1befbe824be5ba333e2f3afec Mon Sep 17 00:00:00 2001 From: delthas Date: Thu, 18 Nov 2021 18:56:04 +0100 Subject: 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). --- app.go | 10 ++++++++-- 1 file 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) { -- cgit v1.2.3