1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Keep an initial order of the currencies so they won't be in a different order after refreshing (#752)

This purely happend due to maps not keeping the order items are in. This way
it at least won't change throughout the runtime of wtfutil. Ideally it would
use and keep the order as specified by the user in the configuration but
right now there is no way to enforce this.
This commit is contained in:
Toon Schoenmakers 2019-11-17 03:47:52 +00:00 committed by Chris Cummer
parent f81c0adb0f
commit c8a14e7685
2 changed files with 6 additions and 2 deletions

View File

@ -16,6 +16,7 @@ type Settings struct {
common *cfg.Common common *cfg.Common
rates map[string][]string `help:"Defines what currency rates we want to know about` rates map[string][]string `help:"Defines what currency rates we want to know about`
order []string
} }
// NewSettingsFromYAML creates a new settings instance from a YAML config block // NewSettingsFromYAML creates a new settings instance from a YAML config block
@ -24,10 +25,12 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
rates: map[string][]string{}, rates: map[string][]string{},
order: []string{},
} }
raw := ymlConfig.UMap("rates", map[string]interface{}{}) raw := ymlConfig.UMap("rates", map[string]interface{}{})
for key, value := range raw { for key, value := range raw {
settings.order = append(settings.order, key)
settings.rates[key] = []string{} settings.rates[key] = []string{}
switch value.(type) { switch value.(type) {
case string: case string:

View File

@ -55,10 +55,11 @@ func (widget *Widget) content() (string, string, bool) {
if widget.err != nil { if widget.err != nil {
out = widget.err.Error() out = widget.err.Error()
} else { } else {
for base, rates := range widget.rates { for base, rates := range widget.settings.rates {
out += fmt.Sprintf("[%s]Rates from %s[white]\n", widget.settings.common.Colors.Subheading, base) out += fmt.Sprintf("[%s]Rates from %s[white]\n", widget.settings.common.Colors.Subheading, base)
idx := 0 idx := 0
for cur, rate := range rates { for _, cur := range rates {
rate := widget.rates[base][cur]
out += fmt.Sprintf("[%s]%s - %f[white]\n", widget.CommonSettings().RowColor(idx), cur, rate) out += fmt.Sprintf("[%s]%s - %f[white]\n", widget.CommonSettings().RowColor(idx), cur, rate)
idx++ idx++
} }