aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/directories.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-13 20:02:21 -0500
committerDrew DeVault <sir@cmpwn.com>2019-01-13 20:02:21 -0500
commita782b709d1312bfe80dda7c864de96ba1c854bc2 (patch)
tree206846b95e787e302694cbc3f812e173eeb76b5e /widgets/directories.go
parentf87fe502a6d252bac9da5f08fd2aa682a9fc2277 (diff)
downloadaerc-a782b709d1312bfe80dda7c864de96ba1c854bc2.tar.gz
Add loading spinner
Diffstat (limited to 'widgets/directories.go')
-rw-r--r--widgets/directories.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/widgets/directories.go b/widgets/directories.go
index 13018bba..11fe2d64 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() {