summaryrefslogtreecommitdiffstats
path: root/colorschemes/registry.go
diff options
context:
space:
mode:
Diffstat (limited to 'colorschemes/registry.go')
-rw-r--r--colorschemes/registry.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/colorschemes/registry.go b/colorschemes/registry.go
index d79271d..8f86491 100644
--- a/colorschemes/registry.go
+++ b/colorschemes/registry.go
@@ -3,8 +3,10 @@ package colorschemes
import (
"encoding/json"
"fmt"
- "io/ioutil"
"path/filepath"
+ "strings"
+
+ "github.com/shibukawa/configdir"
)
var registry map[string]Colorscheme
@@ -15,7 +17,7 @@ func init() {
}
}
-func FromName(confDir string, c string) (Colorscheme, error) {
+func FromName(confDir configdir.ConfigDir, c string) (Colorscheme, error) {
cs, ok := registry[c]
if !ok {
cs, err := getCustomColorscheme(confDir, c)
@@ -34,12 +36,20 @@ func register(name string, c Colorscheme) {
}
// getCustomColorscheme tries to read a custom json colorscheme from <configDir>/<name>.json
-func getCustomColorscheme(confDir string, name string) (Colorscheme, error) {
+func getCustomColorscheme(confDir configdir.ConfigDir, name string) (Colorscheme, error) {
var cs Colorscheme
- filePath := filepath.Join(confDir, name+".json")
- dat, err := ioutil.ReadFile(filePath)
+ fn := name + ".json"
+ folder := confDir.QueryFolderContainsFile(fn)
+ if folder == nil {
+ paths := make([]string, 0)
+ for _, d := range confDir.QueryFolders(configdir.Existing) {
+ paths = append(paths, d.Path)
+ }
+ return cs, fmt.Errorf("failed to find colorscheme file %s in %s", fn, strings.Join(paths, ", "))
+ }
+ dat, err := folder.ReadFile(fn)
if err != nil {
- return cs, fmt.Errorf("failed to read colorscheme file: %v", err)
+ return cs, fmt.Errorf("failed to read colorscheme file %s: %v", filepath.Join(folder.Path, fn), err)
}
err = json.Unmarshal(dat, &cs)
if err != nil {