-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
config.go
57 lines (47 loc) · 1.14 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"github.com/smmr-software/mabel/full"
"github.com/smmr-software/mabel/internal/styles"
"github.com/BurntSushi/toml"
"github.com/adrg/xdg"
)
var (
md toml.MetaData
err error
)
type config struct {
Download string
Port uint
Log bool
RequireEncryption bool `toml:"require-encryption"`
Borderless bool
Theme toml.Primitive
Keys full.CustomKeyMap
}
// getTheme checks the config file for a configured theme key and
// returns a ColorTheme. If the theme key is not present, the function
// returns the default theme.
func (c *config) getTheme() *styles.ColorTheme {
switch md.Type("theme") {
case "String":
var str string
md.PrimitiveDecode(c.Theme, &str)
return styles.StringToTheme(&str)
case "Hash":
var hash styles.CustomTheme
md.PrimitiveDecode(c.Theme, &hash)
return hash.ToTheme()
default:
return &styles.DefaultTheme
}
}
// getConfig checks for a TOML file in the config directory and returns
// a config.
func getConfig() (conf config) {
file := xdg.ConfigHome + "/mabel/config.toml"
md, err = toml.DecodeFile(file, &conf)
if err != nil {
return config{}
}
return conf
}