Embed styles in gold library

This commit is contained in:
Christian Muehlhaeuser
2019-12-06 01:34:27 +01:00
parent 6f31dbf5ec
commit 6fe32ed145
10 changed files with 200 additions and 5 deletions
+27
View File
@@ -2,8 +2,14 @@ package gold
import (
"fmt"
"io"
"io/ioutil"
"os"
"github.com/lucasb-eyer/go-colorful"
"github.com/rakyll/statik/fs"
_ "github.com/charmbracelet/gold/statik"
)
type StyleType int
@@ -63,6 +69,27 @@ type ElementStyle struct {
Suffix string `json:"suffix"`
}
func loadStyle(f string) ([]byte, error) {
var r io.ReadCloser
var err error
r, err = os.Open(f)
if err != nil {
statikFS, err := fs.New()
if err != nil {
return nil, err
}
r, err = statikFS.Open("/" + f + ".json")
if err != nil {
return nil, err
}
}
defer r.Close()
return ioutil.ReadAll(r)
}
func cascadeStyles(onlyColors bool, s ...ElementStyle) ElementStyle {
var r ElementStyle