2020-06-20 04:40:34 +00:00
|
|
|
// Package config provides the repository for configuration and preferences.
|
|
|
|
package config
|
|
|
|
|
2020-06-20 06:55:39 +00:00
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
)
|
|
|
|
|
|
|
|
const ConfigFile = "config.json"
|
2020-06-20 04:40:34 +00:00
|
|
|
|
|
|
|
// List of config sections.
|
|
|
|
type Section uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
Appearance Section = iota
|
|
|
|
sectionLen
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s Section) String() string {
|
|
|
|
switch s {
|
|
|
|
case Appearance:
|
|
|
|
return "Appearance"
|
|
|
|
default:
|
|
|
|
return "???"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var Sections = [sectionLen][]Entry{}
|
|
|
|
|
|
|
|
func sortSection(section Section) {
|
|
|
|
// TODO: remove the sorting and allow for declarative ordering
|
|
|
|
sort.Slice(Sections[section], func(i, j int) bool {
|
|
|
|
return Sections[section][i].Name < Sections[section][j].Name
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type Entry struct {
|
|
|
|
Name string
|
|
|
|
Value EntryValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func AppearanceAdd(name string, value EntryValue) {
|
|
|
|
Sections[Appearance] = append(Sections[Appearance], Entry{
|
|
|
|
Name: name,
|
|
|
|
Value: value,
|
|
|
|
})
|
|
|
|
sortSection(Appearance)
|
|
|
|
}
|
2020-06-20 06:55:39 +00:00
|
|
|
|
|
|
|
func Save() error {
|
|
|
|
return MarshalToFile(ConfigFile, Sections)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Restore() error {
|
|
|
|
return UnmarshalFromFile(ConfigFile, &Sections)
|
|
|
|
}
|