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>
This commit is contained in:
Paul Spooren 2019-08-29 15:30:35 -10:00 committed by Drew DeVault
parent f13f9a8684
commit e4104a8674
5 changed files with 32 additions and 21 deletions

View File

@ -33,6 +33,8 @@ type UIConfig struct {
EmptyDirlist string `ini:"empty-dirlist"` EmptyDirlist string `ini:"empty-dirlist"`
MouseEnabled bool `ini:"mouse-enabled"` MouseEnabled bool `ini:"mouse-enabled"`
NewMessageBell bool `ini:"new-message-bell"` NewMessageBell bool `ini:"new-message-bell"`
Spinner string `ini:"spinner"`
SpinnerDelimiter string `ini:"spinner-delimiter"`
} }
const ( const (
@ -347,6 +349,9 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) {
EmptyDirlist: "(no folders)", EmptyDirlist: "(no folders)",
MouseEnabled: false, MouseEnabled: false,
NewMessageBell: true, NewMessageBell: true,
Spinner:
"[..] , [..] , [..] , [..] , [..], [..] , [..] , [..] ",
SpinnerDelimiter: ",",
}, },
Viewer: ViewerConfig{ Viewer: ViewerConfig{

View File

@ -110,6 +110,21 @@ These options are configured in the *[ui]* section of aerc.conf.
Default: true Default: true
*spinner*
Animation shown while loading, split by spinner-delimiter (below)
Examples:
- spinner = "\-\_-,\_-\_"
- spinner = '. , .'
- spinner = "\,|,/,-"
Default: "[..] , [..] , [..] , [..] , [..], [..] , [..] , [..] "
*spinner-delimiter*
Spinner delimiter to split string into a animation
Default: ","
## VIEWER ## VIEWER
These options are configured in the *[viewer]* section of aerc.conf. These options are configured in the *[viewer]* section of aerc.conf.

View File

@ -33,7 +33,7 @@ func NewDirectoryList(acctConf *config.AccountConfig, uiConf *config.UIConfig,
acctConf: acctConf, acctConf: acctConf,
uiConf: uiConf, uiConf: uiConf,
logger: logger, logger: logger,
spinner: NewSpinner(), spinner: NewSpinner(uiConf),
store: lib.NewDirStore(), store: lib.NewDirStore(),
worker: worker, worker: worker,
} }

View File

@ -59,7 +59,7 @@ func NewMessageList(conf *config.AercConfig, logger *log.Logger) *MessageList {
ml := &MessageList{ ml := &MessageList{
conf: conf, conf: conf,
logger: logger, logger: logger,
spinner: NewSpinner(), spinner: NewSpinner(&conf.Ui),
isInitalizing: true, isInitalizing: true,
} }
ml.spinner.OnInvalidate(func(_ ui.Drawable) { ml.spinner.OnInvalidate(func(_ ui.Drawable) {

View File

@ -3,35 +3,26 @@ package widgets
import ( import (
"sync/atomic" "sync/atomic"
"time" "time"
"strings"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"git.sr.ht/~sircmpwn/aerc/config"
"git.sr.ht/~sircmpwn/aerc/lib/ui" "git.sr.ht/~sircmpwn/aerc/lib/ui"
) )
var (
frames = []string{
"[..] ",
" [..] ",
" [..] ",
" [..] ",
" [..]",
" [..] ",
" [..] ",
" [..] ",
}
)
type Spinner struct { type Spinner struct {
ui.Invalidatable ui.Invalidatable
frame int64 // access via atomic frame int64 // access via atomic
frames []string
stop chan struct{} stop chan struct{}
} }
func NewSpinner() *Spinner { func NewSpinner(uiConf *config.UIConfig) *Spinner {
spinner := Spinner{ spinner := Spinner{
stop: make(chan struct{}), stop: make(chan struct{}),
frame: -1, frame: -1,
frames: strings.Split(uiConf.Spinner, uiConf.SpinnerDelimiter),
} }
return &spinner return &spinner
} }
@ -77,11 +68,11 @@ func (s *Spinner) Draw(ctx *ui.Context) {
s.Start() 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) ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
col := ctx.Width()/2 - len(frames[0])/2 + 1 col := ctx.Width()/2 - len(s.frames[0])/2 + 1
ctx.Printf(col, 0, tcell.StyleDefault, "%s", frames[cur]) ctx.Printf(col, 0, tcell.StyleDefault, "%s", s.frames[cur])
} }
func (s *Spinner) Invalidate() { func (s *Spinner) Invalidate() {