diff options
author | Paul Spooren <mail@aparcar.org> | 2019-08-29 15:30:35 -1000 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-08-30 10:32:28 +0900 |
commit | e4104a867401e383ef2b45f4c449b8b3fa25e69b (patch) | |
tree | 74a0ec139b3630e1f9963122d3ffa2809aaf0616 /widgets | |
parent | f13f9a86849ff8b4616aa7b462ed171833e02a95 (diff) |
Allow custom spinner via config file
Allows to set `ui.spinner=` to a string which is then split by
`ui.spinner-delimiter=` (Default: comma) instead of having a hard coded
animation.
This implementation doesn't use INIs capabilities to split strings as
it trims whitespaces breaking the default animation.
Signed-off-by: Paul Spooren <mail@aparcar.org>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/dirlist.go | 2 | ||||
-rw-r--r-- | widgets/msglist.go | 2 | ||||
-rw-r--r-- | widgets/spinner.go | 29 |
3 files changed, 12 insertions, 21 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go index 6214c8e..33119dd 100644 --- a/widgets/dirlist.go +++ b/widgets/dirlist.go @@ -33,7 +33,7 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig, acctConf: acctConf, uiConf: uiConf, logger: logger, - spinner: NewSpinner(), + spinner: NewSpinner(uiConf), store: lib.NewDirStore(), worker: worker, } diff --git a/widgets/msglist.go b/widgets/msglist.go index df83dbd..a316cf5 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -59,7 +59,7 @@ func NewMessageList(conf *config.AercConfig, logger *log.Logger) *MessageList { ml := &MessageList{ conf: conf, logger: logger, - spinner: NewSpinner(), + spinner: NewSpinner(&conf.Ui), isInitalizing: true, } ml.spinner.OnInvalidate(func(_ ui.Drawable) { diff --git a/widgets/spinner.go b/widgets/spinner.go index 56f75cd..be95d39 100644 --- a/widgets/spinner.go +++ b/widgets/spinner.go @@ -3,35 +3,26 @@ package widgets import ( "sync/atomic" "time" + "strings" "github.com/gdamore/tcell" + "git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/lib/ui" ) -var ( - frames = []string{ - "[..] ", - " [..] ", - " [..] ", - " [..] ", - " [..]", - " [..] ", - " [..] ", - " [..] ", - } -) - type Spinner struct { ui.Invalidatable frame int64 // access via atomic + frames []string stop chan struct{} } -func NewSpinner() *Spinner { +func NewSpinner(uiConf *config.UIConfig) *Spinner { spinner := Spinner{ - stop: make(chan struct{}), - frame: -1, + stop: make(chan struct{}), + frame: -1, + frames: strings.Split(uiConf.Spinner, uiConf.SpinnerDelimiter), } return &spinner } @@ -77,11 +68,11 @@ func (s *Spinner) Draw(ctx *ui.Context) { s.Start() } - cur := int(atomic.LoadInt64(&s.frame) % int64(len(frames))) + cur := int(atomic.LoadInt64(&s.frame) % int64(len(s.frames))) ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault) - col := ctx.Width()/2 - len(frames[0])/2 + 1 - ctx.Printf(col, 0, tcell.StyleDefault, "%s", frames[cur]) + col := ctx.Width()/2 - len(s.frames[0])/2 + 1 + ctx.Printf(col, 0, tcell.StyleDefault, "%s", s.frames[cur]) } func (s *Spinner) Invalidate() { |