aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/spinner.go
diff options
context:
space:
mode:
authorDean <gao.dean@hotmail.com>2023-01-11 14:33:11 +1100
committerRobin Jarry <robin@jarry.cc>2023-01-11 14:13:14 +0100
commitd73f50f272de210fe4957ff107e1ff88887f1c20 (patch)
tree8d954aacd76c3db81a78aff64ca2bc47f4951deb /widgets/spinner.go
parentc6142b2267f689d5be893f6750e514fa9ba5f93c (diff)
downloadaerc-d73f50f272de210fe4957ff107e1ff88887f1c20.tar.gz
spinner: add spinner-interval config option
The default 200ms between each spinner frame can be unsuitable for spinners with many frames, so this adds a spinner-interval config option with type `time.Duration` to specify the interval between frames. The default is still the usual 200ms. Signed-off-by: Dean <gao.dean@hotmail.com> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'widgets/spinner.go')
-rw-r--r--widgets/spinner.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/widgets/spinner.go b/widgets/spinner.go
index 99365527..abbe1ae4 100644
--- a/widgets/spinner.go
+++ b/widgets/spinner.go
@@ -13,18 +13,20 @@ import (
)
type Spinner struct {
- frame int64 // access via atomic
- frames []string
- stop chan struct{}
- style tcell.Style
+ frame int64 // access via atomic
+ frames []string
+ interval time.Duration
+ stop chan struct{}
+ style tcell.Style
}
func NewSpinner(uiConf *config.UIConfig) *Spinner {
spinner := Spinner{
- stop: make(chan struct{}),
- frame: -1,
- frames: strings.Split(uiConf.Spinner, uiConf.SpinnerDelimiter),
- style: uiConf.GetStyle(config.STYLE_SPINNER),
+ stop: make(chan struct{}),
+ frame: -1,
+ interval: uiConf.SpinnerInterval,
+ frames: strings.Split(uiConf.Spinner, uiConf.SpinnerDelimiter),
+ style: uiConf.GetStyle(config.STYLE_SPINNER),
}
return &spinner
}
@@ -45,7 +47,7 @@ func (s *Spinner) Start() {
atomic.StoreInt64(&s.frame, -1)
s.stop <- struct{}{}
return
- case <-time.After(200 * time.Millisecond):
+ case <-time.After(s.interval):
atomic.AddInt64(&s.frame, 1)
ui.QueueRedraw()
}