aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
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
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')
-rw-r--r--widgets/account.go17
-rw-r--r--widgets/aerc.go34
-rw-r--r--widgets/spinner.go1
-rw-r--r--widgets/terminal.go1
4 files changed, 19 insertions, 34 deletions
diff --git a/widgets/account.go b/widgets/account.go
index c131f335..93a75973 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -74,7 +74,7 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
{Strategy: ui.SIZE_WEIGHT, Size: ui.Const(1)},
})
- worker, err := worker.NewWorker(acct.Source)
+ worker, err := worker.NewWorker(acct.Source, acct.Name)
if err != nil {
host.SetError(fmt.Sprintf("%s: %s", acct.Name, err))
logging.Errorf("%s: %v", acct.Name, err)
@@ -110,20 +110,6 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
return view, nil
}
-func (acct *AccountView) Tick() bool {
- if acct.worker == nil {
- return false
- }
- select {
- case msg := <-acct.worker.Messages:
- msg = acct.worker.ProcessMessage(msg)
- acct.onMessage(msg)
- return true
- default:
- return false
- }
-}
-
func (acct *AccountView) SetStatus(setters ...statusline.SetStateFunc) {
for _, fn := range setters {
fn(acct.state, acct.SelectedDirectory())
@@ -236,6 +222,7 @@ func (acct *AccountView) isSelected() bool {
}
func (acct *AccountView) onMessage(msg types.WorkerMessage) {
+ msg = acct.worker.ProcessMessage(msg)
switch msg := msg.(type) {
case *types.Done:
switch msg.InResponseTo().(type) {
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 {
diff --git a/widgets/spinner.go b/widgets/spinner.go
index f2607727..0e7c9005 100644
--- a/widgets/spinner.go
+++ b/widgets/spinner.go
@@ -49,6 +49,7 @@ func (s *Spinner) Start() {
case <-time.After(200 * time.Millisecond):
atomic.AddInt64(&s.frame, 1)
s.Invalidate()
+ ui.QueueRedraw()
}
}
}()
diff --git a/widgets/terminal.go b/widgets/terminal.go
index b854a288..82954a70 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -169,6 +169,7 @@ func (term *Terminal) HandleEvent(ev tcell.Event) bool {
}
case *tcellterm.EventClosed:
term.Close(nil)
+ ui.QueueRedraw()
}
return false
}