1 // This file is a part of git.thekondor.net/zvuchno.git (mirror: github.com/thekondor/zvuchno)
12 type notificationConfigSection struct {
16 type appearanceConfigSection struct {
17 Width byte `yaml:"width,omitempty"`
18 Format formatConfigSection `yaml:"format,omitempty"`
19 Text textConfigSection `yaml:"text,omitempty"`
22 type formatConfigSection struct {
23 Full string `yaml:"full,omitempty"`
24 Bar string `yaml:"bar,omitempty"`
27 type textConfigSection struct {
28 Title string `yaml:"title"`
29 OnMute string `yaml:"on_mute"`
30 OnUnmute string `yaml:"on_unmute"`
34 Notification notificationConfigSection `yaml:"notification,omitempty"`
35 Appearance appearanceConfigSection `yaml:"appearance,omitempty"`
38 func NewConfig() *Config {
39 configPath := locateConfigPath()
40 log.Printf(`Config = %s`, configPath)
42 self, err := newConfig(configPath)
44 log.Printf("W: Failed to load config: %s, default values to be used", err)
50 func locateConfigPath() string {
51 configPath := "${HOME}/.zvuchno.yml"
52 if _, ok := os.LookupEnv("XDG_CONFIG_HOME"); ok {
53 configPath = "${XDG_CONFIG_HOME}/zvuchno.yml"
56 return os.ExpandEnv(configPath)
59 func newConfig(path string) (*Config, error) {
61 Notification: notificationConfigSection{
64 Appearance: appearanceConfigSection{
66 Format: formatConfigSection{
67 Full: "{{ .Percent }}% {{ .Bar }}",
70 Text: textConfigSection{
73 OnUnmute: "🔈 unmuted",
78 file, err := ioutil.ReadFile(path)
83 err = yaml.Unmarshal(file, self)