From c8a14e76859a094cc57ba73e9a95d0f04e6f8835 Mon Sep 17 00:00:00 2001 From: Toon Schoenmakers Date: Sun, 17 Nov 2019 03:47:52 +0000 Subject: [PATCH] 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. --- modules/exchangerates/settings.go | 3 +++ modules/exchangerates/widget.go | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/exchangerates/settings.go b/modules/exchangerates/settings.go index ffdd6c6f..bc14ace9 100644 --- a/modules/exchangerates/settings.go +++ b/modules/exchangerates/settings.go @@ -16,6 +16,7 @@ type Settings struct { common *cfg.Common 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 @@ -24,10 +25,12 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), rates: map[string][]string{}, + order: []string{}, } raw := ymlConfig.UMap("rates", map[string]interface{}{}) for key, value := range raw { + settings.order = append(settings.order, key) settings.rates[key] = []string{} switch value.(type) { case string: diff --git a/modules/exchangerates/widget.go b/modules/exchangerates/widget.go index 14f43167..bf2f2404 100644 --- a/modules/exchangerates/widget.go +++ b/modules/exchangerates/widget.go @@ -55,10 +55,11 @@ func (widget *Widget) content() (string, string, bool) { if widget.err != nil { out = widget.err.Error() } 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) 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) idx++ }