-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.go
65 lines (52 loc) · 1.27 KB
/
theme.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
58
59
60
61
62
63
64
65
package main
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/kovetskiy/ko"
"github.com/reconquest/karma-go"
yaml "gopkg.in/coryb/yaml.v2"
)
type Theme struct {
Identifier string `required:"true"`
Candidate struct {
Normal string `required:"true"`
Selected string `required:"true"`
// Nested string `required:"true"`
} `required:"true"`
Fog struct {
Text string `required:"true"`
Background string `required:"true"`
}
}
var (
defaultUserThemePath = `~/.config/tmux-autocomplete/themes/`
defaultThemePath = defaultSystemThemePath + `:` + defaultUserThemePath
)
func LoadTheme(dirs string, name string) (*Theme, error) {
var theme Theme
for _, dir := range strings.Split(dirs, ":") {
if dir == "" {
return nil, fmt.Errorf("empty directory with themes specified")
}
if strings.HasPrefix(dir, "~/") {
// 1 because need to trim only ~ symbol, slash is required
dir = os.Getenv("HOME") + dir[1:]
}
path := filepath.Join(dir, name+".theme")
err := ko.Load(path, &theme, yaml.Unmarshal)
if err != nil {
if os.IsNotExist(err) {
continue
}
return nil, karma.Format(
err,
"unable to read theme file: %s", path,
)
}
return &theme, nil
}
return nil, errors.New("no such theme found")
}