aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-09-12 16:09:19 -0500
committerRobin Jarry <robin@jarry.cc>2022-09-13 23:58:54 +0200
commitc947811e9f7a3421212287cbe9fce125aa059467 (patch)
treeb347bb9d142538d2c37a06cfb4062395b48fef35 /lib/ui
parentfad90c2956c6e57fd8da83da9c218b35cf2a2f93 (diff)
downloadaerc-c947811e9f7a3421212287cbe9fce125aa059467.tar.gz
ui: process tcell events in a separate go routine from rendering
The UI runs off a 16 ms ticker. If no render is required, and no event is seen, aerc waits 16 ms before checking for new events or render requests. This severely limits handling of events from tcell, and is particularly noticeable on pasting of large quantities of text. Process tcell events in a separate go routine from the render loop. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/ui.go33
1 files changed, 16 insertions, 17 deletions
diff --git a/lib/ui/ui.go b/lib/ui/ui.go
index 596000a5..7cff5754 100644
--- a/lib/ui/ui.go
+++ b/lib/ui/ui.go
@@ -85,23 +85,6 @@ func (state *UI) Close() {
func (state *UI) Tick() bool {
more := false
- select {
- case event := <-state.tcEvents:
- if event, ok := event.(*tcell.EventResize); ok {
- state.screen.Clear()
- width, height := event.Size()
- state.ctx = NewContext(width, height, state.screen, state.onPopover)
- state.Content.Invalidate()
- }
- // if we have a popover, and it can handle the event, it does so
- if state.popover == nil || !state.popover.Event(event) {
- // otherwise, we send the event to the main content
- state.Content.Event(event)
- }
- more = true
- default:
- }
-
wasInvalid := atomic.SwapInt32(&state.invalid, 0)
if wasInvalid != 0 {
if state.popover != nil {
@@ -126,3 +109,19 @@ func (state *UI) Tick() bool {
func (state *UI) EnableMouse() {
state.screen.EnableMouse()
}
+
+func (state *UI) Run() {
+ for event := range state.tcEvents {
+ if event, ok := event.(*tcell.EventResize); ok {
+ state.screen.Clear()
+ width, height := event.Size()
+ state.ctx = NewContext(width, height, state.screen, state.onPopover)
+ state.Content.Invalidate()
+ }
+ // if we have a popover, and it can handle the event, it does so
+ if state.popover == nil || !state.popover.Event(event) {
+ // otherwise, we send the event to the main content
+ state.Content.Event(event)
+ }
+ }
+}