Reading directly from the event channel instead of using `PollEvent`
khamidou opened this issue · 2 comments
Hi @gdamore – thank you for building tcell, it's a great library! I'm building an app that makes requests that can take several dozen seconds. I'd like to display some loading animation during the time. My code looks a bit like this:
func updateLoadingScreen(s tcell.Screen, ch chan bool) {
ticker := time.NewTicker(1 * time.Second)
for {
select {
case <-ch:
return
case <-ticker.C:
// update loading animation
}
}
}
I'd like to be able to also handle keyboard events so users can exit if the request is taking too much time. However, given that PollEvent
is blocking, my animation won't update while we wait for a keyboard event.
Looking at the PollEvent
code I see that it's just a blocking select
over evch
. Have you considered adding a method to the Screen
interface that would return a reference evch
instead?
btw I'd be happy to contribute a patch for this if you think it's a valid enhancement.
Hey khamidou -
Checkout screen.ChannelEvents
. You provide a channel and tcell will send it's events on it.
Oh interesting, thank you @rockorager!