diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-01-13 20:02:21 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-01-13 20:02:21 -0500 |
commit | a782b709d1312bfe80dda7c864de96ba1c854bc2 (patch) | |
tree | 206846b95e787e302694cbc3f812e173eeb76b5e /widgets/directories.go | |
parent | f87fe502a6d252bac9da5f08fd2aa682a9fc2277 (diff) | |
download | aerc-a782b709d1312bfe80dda7c864de96ba1c854bc2.tar.gz |
Add loading spinner
Diffstat (limited to 'widgets/directories.go')
-rw-r--r-- | widgets/directories.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/widgets/directories.go b/widgets/directories.go index 13018bb..11fe2d6 100644 --- a/widgets/directories.go +++ b/widgets/directories.go @@ -17,13 +17,24 @@ type DirectoryList struct { logger *log.Logger onInvalidate func(d ui.Drawable) selected string + spinner *Spinner worker *types.Worker } func NewDirectoryList(conf *config.AccountConfig, logger *log.Logger, worker *types.Worker) *DirectoryList { - return &DirectoryList{conf: conf, logger: logger, worker: worker} + dirlist := &DirectoryList{ + conf: conf, + logger: logger, + spinner: NewSpinner(), + worker: worker, + } + dirlist.spinner.OnInvalidate(func(_ ui.Drawable) { + dirlist.Invalidate() + }) + dirlist.spinner.Start() + return dirlist } func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) { @@ -37,6 +48,7 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) { case *types.Done: sort.Strings(dirs) dirlist.dirs = dirs + dirlist.spinner.Stop() dirlist.Invalidate() if done != nil { done(dirs) @@ -63,6 +75,12 @@ func (dirlist *DirectoryList) Invalidate() { func (dirlist *DirectoryList) Draw(ctx *ui.Context) { ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault) + + if dirlist.spinner.IsRunning() { + dirlist.spinner.Draw(ctx) + return + } + row := 0 for _, name := range dirlist.dirs { if row >= ctx.Height() { |