X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=internal%2Fconfig%2Frtfiles.go;h=4ce263e9e97dacb0916cfa2be17015c66f36ddc8;hb=9aaafe5dcf2c761b398e5caefc198dfb73521c27;hp=6070e4eb81fbcabe24c2f28fddf8b7be693f5040;hpb=016b8dcc4c784f3c1288fdbe8e4bceaa8bf34ebd;p=micro.git diff --git a/internal/config/rtfiles.go b/internal/config/rtfiles.go index 6070e4eb..4ce263e9 100644 --- a/internal/config/rtfiles.go +++ b/internal/config/rtfiles.go @@ -17,10 +17,13 @@ const ( RTHelp = 2 RTPlugin = 3 RTSyntaxHeader = 4 - NumTypes = 5 // How many filetypes are there ) -type RTFiletype byte +var ( + NumTypes = 5 // How many filetypes are there +) + +type RTFiletype int // RuntimeFile allows the program to read runtime data like colorschemes or syntax files type RuntimeFile interface { @@ -31,8 +34,20 @@ type RuntimeFile interface { } // allFiles contains all available files, mapped by filetype -var allFiles [NumTypes][]RuntimeFile -var realFiles [NumTypes][]RuntimeFile +var allFiles [][]RuntimeFile +var realFiles [][]RuntimeFile + +func init() { + allFiles = make([][]RuntimeFile, NumTypes) + realFiles = make([][]RuntimeFile, NumTypes) +} + +func NewRTFiletype() int { + NumTypes++ + allFiles = append(allFiles, []RuntimeFile{}) + realFiles = append(realFiles, []RuntimeFile{}) + return NumTypes - 1 +} // some file on filesystem type realFile string @@ -176,12 +191,16 @@ func InitRuntimeFiles() { for _, f := range srcs { if strings.HasSuffix(f.Name(), ".lua") { p.Srcs = append(p.Srcs, realFile(filepath.Join(plugdir, d.Name(), f.Name()))) - } else if f.Name() == "info.json" { - data, err := ioutil.ReadFile(filepath.Join(plugdir, d.Name(), "info.json")) + } else if strings.HasSuffix(f.Name(), ".json") { + data, err := ioutil.ReadFile(filepath.Join(plugdir, d.Name(), f.Name())) if err != nil { continue } - p.Info, _ = NewPluginInfo(data) + p.Info, err = NewPluginInfo(data) + if err != nil { + log.Println(err) + continue + } p.Name = p.Info.Name } } @@ -205,12 +224,16 @@ func InitRuntimeFiles() { for _, f := range srcs { if strings.HasSuffix(f, ".lua") { p.Srcs = append(p.Srcs, assetFile(filepath.Join(plugdir, d, f))) - } else if f == "info.json" { - data, err := Asset(filepath.Join(plugdir, d, "info.json")) + } else if strings.HasSuffix(f, ".json") { + data, err := Asset(filepath.Join(plugdir, d, f)) + if err != nil { + continue + } + p.Info, err = NewPluginInfo(data) if err != nil { + log.Println(err) continue } - p.Info, _ = NewPluginInfo(data) p.Name = p.Info.Name } }