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:
parent
f81c0adb0f
commit
c8a14e7685
@ -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:
|
||||
|
@ -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++
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user