1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-12-23 20:56:42 +00:00
cchat-gtk/internal/ui/config/config.go

56 lines
995 B
Go
Raw Normal View History

2020-06-20 04:40:34 +00:00
// Package config provides the repository for configuration and preferences.
package config
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)
}
func Save() error {
return MarshalToFile(ConfigFile, Sections)
}
func Restore() error {
return UnmarshalFromFile(ConfigFile, &Sections)
}