From ebf3bcc76be9a7252623e87c349bdb27b47ca3c4 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 5 Sep 2020 12:36:31 +0300 Subject: [PATCH] resume with a new goroutine instead of busy wait Related #461 --- ui.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ui.go b/ui.go index 451a4fd..de19fe4 100644 --- a/ui.go +++ b/ui.go @@ -520,17 +520,22 @@ func newUI(screen tcell.Screen) *ui { icons: parseIcons(), } - go func() { - var ev tcell.Event - for { - ev = ui.screen.PollEvent() - ui.evChan <- ev - } - }() + go ui.pollEvents() return ui } +func (ui *ui) pollEvents() { + var ev tcell.Event + for { + ev = ui.screen.PollEvent() + if ev == nil { + return + } + ui.evChan <- ev + } +} + func (ui *ui) renew() { wtot, htot := ui.screen.Size() @@ -1058,6 +1063,8 @@ func (ui *ui) resume() { ui.screen = screen + go ui.pollEvents() + ui.renew() }