From 73ae475a7dd5ae9cb27ad738edfd88ca4c02e108 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 26 Nov 2022 22:49:02 -0500 Subject: [PATCH] Fixed some bugs related to saving conf files --- config/config.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 3407f30..1cf2faa 100644 --- a/config/config.go +++ b/config/config.go @@ -3,6 +3,7 @@ package config import "io" import "os" import "fmt" +import "sort" import "bufio" import "strings" import "strconv" @@ -267,18 +268,27 @@ func (config *Config) Save (name string) (err error) { // SaveTo writes the configuration data to the specified io.Writer. func (config *Config) SaveTo (writer io.Writer) (err error) { - for key, value := range config.Parameters { + keys := make([]string, len(config.Parameters)) + index := 0 + for key, _ := range config.Parameters { + keys[index] = key + index ++ + } + sort.Strings(keys) + + for _, key := range keys { + value := config.Parameters[key] switch value.(type) { case string: fmt.Fprintf(writer,"%s: %s\n", key, value.(string)) case color.RGBA: colorValue := value.(color.RGBA) - colorInt := uint64 ( - colorValue.R << 16 | - colorValue.G << 8 | - colorValue.B) - fmt.Fprintf(writer,"%s: #%x\n", key, colorInt) + colorInt := + uint64(colorValue.R) << 16 | + uint64(colorValue.G) << 8 | + uint64(colorValue.B) + fmt.Fprintf(writer,"%s: #%06x\n", key, colorInt) case int: fmt.Fprintf(writer,"%s: %d\n", key, value.(int))