aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/aerc.go
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 /widgets/aerc.go
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 'widgets/aerc.go')
-rw-r--r--widgets/aerc.go34
1 files changed, 15 insertions, 19 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index bdd18dd5..b396cf5e 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -20,6 +20,7 @@ import (
"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"
)
type Aerc struct {
@@ -145,26 +146,10 @@ func (aerc *Aerc) Beep() {
}
}
-func (aerc *Aerc) Tick() bool {
- more := false
- for _, acct := range aerc.accounts {
- more = acct.Tick() || more
- }
-
- if len(aerc.prompts.Children()) > 0 {
- more = true
- previous := aerc.focused
- prompt := aerc.prompts.Pop().(*ExLine)
- prompt.finish = func() {
- aerc.statusbar.Pop()
- aerc.focus(previous)
- }
-
- aerc.statusbar.Push(prompt)
- aerc.focus(prompt)
+func (aerc *Aerc) HandleMessage(msg types.WorkerMessage) {
+ if acct, ok := aerc.accounts[msg.Account()]; ok {
+ acct.onMessage(msg)
}
-
- return more
}
func (aerc *Aerc) OnInvalidate(onInvalidate func(d ui.Drawable)) {
@@ -182,6 +167,17 @@ func (aerc *Aerc) Focus(focus bool) {
}
func (aerc *Aerc) Draw(ctx *ui.Context) {
+ if len(aerc.prompts.Children()) > 0 {
+ previous := aerc.focused
+ prompt := aerc.prompts.Pop().(*ExLine)
+ prompt.finish = func() {
+ aerc.statusbar.Pop()
+ aerc.focus(previous)
+ }
+
+ aerc.statusbar.Push(prompt)
+ aerc.focus(prompt)
+ }
aerc.grid.Draw(ctx)
if aerc.dialog != nil {
if w, h := ctx.Width(), ctx.Height(); w > 8 && h > 4 {