aboutsummaryrefslogtreecommitdiff
path: root/widgets/msglist.go
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/msglist.go')
-rw-r--r--widgets/msglist.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/widgets/msglist.go b/widgets/msglist.go
index 370ba85..8e3c2eb 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -1,6 +1,12 @@
package widgets
import (
+ "log"
+
+ "github.com/gdamore/tcell"
+
+ "git.sr.ht/~sircmpwn/aerc2/config"
+ "git.sr.ht/~sircmpwn/aerc2/lib/ui"
"git.sr.ht/~sircmpwn/aerc2/worker/types"
)
@@ -34,3 +40,86 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
break
}
}
+
+type MessageList struct {
+ conf *config.AercConfig
+ logger *log.Logger
+ onInvalidate func(d ui.Drawable)
+ spinner *Spinner
+ store *MessageStore
+ worker *types.Worker
+}
+
+// TODO: fish in config
+func NewMessageList(logger *log.Logger, worker *types.Worker) *MessageList {
+ ml := &MessageList{
+ logger: logger,
+ spinner: NewSpinner(),
+ worker: worker,
+ }
+ ml.spinner.OnInvalidate(func(_ ui.Drawable) {
+ ml.Invalidate()
+ })
+ // TODO: stop spinner, probably
+ ml.spinner.Start()
+ return ml
+}
+
+func (ml *MessageList) OnInvalidate(onInvalidate func(d ui.Drawable)) {
+ ml.onInvalidate = onInvalidate
+}
+
+func (ml *MessageList) Invalidate() {
+ if ml.onInvalidate != nil {
+ ml.onInvalidate(ml)
+ }
+}
+
+func (ml *MessageList) Draw(ctx *ui.Context) {
+ ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+
+ if ml.store == nil {
+ ml.spinner.Draw(ctx)
+ return
+ }
+
+ var (
+ needsHeaders []uint64
+ row int = 0
+ )
+
+ for uid, msg := range ml.store.Messages {
+ if row >= ctx.Height() {
+ break
+ }
+
+ if msg == nil {
+ needsHeaders = append(needsHeaders, uid)
+ ml.spinner.Draw(ctx.Subcontext(0, row, ctx.Width(), 1))
+ }
+
+ row += 1
+ }
+
+ if len(needsHeaders) != 0 {
+ ml.spinner.Start()
+ } else {
+ ml.spinner.Stop()
+ }
+
+ // TODO: Fetch these messages
+}
+
+func (ml *MessageList) SetStore(store *MessageStore) {
+ if ml.store == store {
+ return
+ }
+
+ ml.store = store
+ if store != nil {
+ ml.spinner.Stop()
+ } else {
+ ml.spinner.Start()
+ }
+ ml.Invalidate()
+}