aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-10-06 11:46:41 -0500
committerRobin Jarry <robin@jarry.cc>2022-10-07 10:51:53 +0200
commitbb1249164d8de6d821dcf3293f5ff2650be95481 (patch)
tree8dd0194a877a226a976baeb253cb1fe9d77fa70e /lib
parentd847073bdf67a2fd8c8695dbacbe010bcbfd27c8 (diff)
downloadaerc-bb1249164d8de6d821dcf3293f5ff2650be95481.tar.gz
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 <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/msgstore.go2
-rw-r--r--lib/ui/textinput.go1
-rw-r--r--lib/ui/ui.go34
3 files changed, 21 insertions, 16 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 74a021a7..23fbb8f8 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -7,6 +7,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/marker"
"git.sr.ht/~rjarry/aerc/lib/sort"
+ "git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -394,6 +395,7 @@ func (store *MessageStore) runThreadBuilder() {
}
store.threadBuilderDebounce = time.AfterFunc(store.threadBuilderDelay, func() {
store.runThreadBuilderNow()
+ ui.QueueRedraw()
})
}
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index ce8ccc55..d99871ce 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -314,6 +314,7 @@ func (ti *TextInput) showCompletions() {
ti.completions, ti.prefix = ti.tabcomplete(ti.StringLeft())
ti.completeIndex = -1
ti.Invalidate()
+ QueueRedraw()
}
func (ti *TextInput) OnChange(onChange func(ti *TextInput)) {
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)
}
}