diff options
author | delthas <delthas@dille.cc> | 2021-11-18 18:56:04 +0100 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-11-18 19:06:21 +0100 |
commit | 06fbb04b4c0628c1befbe824be5ba333e2f3afec (patch) | |
tree | 055a2e4ddca200d045b720726a8a7ff1657330d9 /app.go | |
parent | OK 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.go | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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) { |