From bb1249164d8de6d821dcf3293f5ff2650be95481 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Thu, 6 Oct 2022 11:46:41 -0500 Subject: aerc: use single event loop Combine tcell events with WorkerMessages to better synchronize state with IO and UI. Remove Tick loop for rendering. Use events to trigger renders. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- lib/ui/ui.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'lib/ui/ui.go') diff --git a/lib/ui/ui.go b/lib/ui/ui.go index d477242e..e29ab13c 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -3,7 +3,6 @@ package ui import ( "sync/atomic" - "git.sr.ht/~rjarry/aerc/logging" "github.com/gdamore/tcell/v2" ) @@ -108,21 +107,24 @@ func (state *UI) EnableMouse() { state.screen.EnableMouse() } -func (state *UI) ProcessEvents() { - defer logging.PanicHandler() - - for !state.ShouldExit() { - event := state.screen.PollEvent() - 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) +func (state *UI) ChannelEvents() { + go func() { + for { + MsgChannel <- state.screen.PollEvent() } + }() +} + +func (state *UI) HandleEvent(event tcell.Event) { + 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) } } -- cgit