From 9570f4b4d0cdf525ce1695971636a0b58f1a091b Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Wed, 31 Jul 2019 09:50:07 +0200 Subject: msglist: add initialization state Make the msglist aware of whether we are still initializing or not. We never stopped spinning the msglist if we didn't get any Directories back from types.ListDirectories. With this change, we can set the init state from the account and display the spinner only if we don't know whether we have directories or not and else the "no messages" string from the config. --- widgets/account.go | 2 ++ widgets/msglist.go | 46 +++++++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 15 deletions(-) (limited to 'widgets') diff --git a/widgets/account.go b/widgets/account.go index de81ab8..07b5010 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -147,6 +147,8 @@ func (acct *AccountView) connected(msg types.WorkerMessage) { if dir != "" { acct.dirlist.Select(dir) } + + acct.msglist.SetInitDone() acct.logger.Println("Connected.") acct.host.SetStatus("Connected.") }) diff --git a/widgets/msglist.go b/widgets/msglist.go index abf6921..9900a32 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -16,20 +16,22 @@ import ( type MessageList struct { ui.Invalidatable - conf *config.AercConfig - logger *log.Logger - height int - scroll int - nmsgs int - spinner *Spinner - store *lib.MessageStore + conf *config.AercConfig + logger *log.Logger + height int + scroll int + nmsgs int + spinner *Spinner + store *lib.MessageStore + isInitalizing bool } func NewMessageList(conf *config.AercConfig, logger *log.Logger) *MessageList { ml := &MessageList{ - conf: conf, - logger: logger, - spinner: NewSpinner(), + conf: conf, + logger: logger, + spinner: NewSpinner(), + isInitalizing: true, } ml.spinner.OnInvalidate(func(_ ui.Drawable) { ml.Invalidate() @@ -49,8 +51,14 @@ func (ml *MessageList) Draw(ctx *ui.Context) { store := ml.Store() if store == nil { - ml.spinner.Draw(ctx) - return + if ml.isInitalizing { + ml.spinner.Draw(ctx) + return + } else { + ml.spinner.Stop() + ml.drawEmptyMessage(ctx) + return + } } var ( @@ -111,9 +119,7 @@ func (ml *MessageList) Draw(ctx *ui.Context) { } if len(uids) == 0 { - msg := ml.conf.Ui.EmptyMessage - ctx.Printf((ctx.Width()/2)-(len(msg)/2), 0, - tcell.StyleDefault, "%s", msg) + ml.drawEmptyMessage(ctx) } if len(needsHeaders) != 0 { @@ -171,6 +177,10 @@ func (ml *MessageList) SetStore(store *lib.MessageStore) { ml.Invalidate() } +func (ml *MessageList) SetInitDone() { + ml.isInitalizing = false +} + func (ml *MessageList) Store() *lib.MessageStore { return ml.store } @@ -209,3 +219,9 @@ func (ml *MessageList) Scroll() { } ml.Invalidate() } + +func (ml *MessageList) drawEmptyMessage(ctx *ui.Context) { + msg := ml.conf.Ui.EmptyMessage + ctx.Printf((ctx.Width()/2)-(len(msg)/2), 0, + tcell.StyleDefault, "%s", msg) +} -- cgit 1.4.1-2-gfad0