Read default styles before reading from the file system (#73)

This commit is contained in:
Jesse Millar
2020-07-24 19:46:18 +02:00
committed by GitHub
parent 28b4a5ca52
commit 1246d13c16
+5 -8
View File
@@ -135,20 +135,17 @@ func WithEnvironmentConfig() TermRendererOption {
// standard style. // standard style.
func WithStylePath(stylePath string) TermRendererOption { func WithStylePath(stylePath string) TermRendererOption {
return func(tr *TermRenderer) error { return func(tr *TermRenderer) error {
jsonBytes, err := ioutil.ReadFile(stylePath)
switch {
case err == nil:
return json.Unmarshal(jsonBytes, &tr.ansiOptions.Styles)
case os.IsNotExist(err):
styles, err := getDefaultStyle(stylePath) styles, err := getDefaultStyle(stylePath)
if err != nil {
jsonBytes, err := ioutil.ReadFile(stylePath)
if err != nil { if err != nil {
return err return err
} }
return json.Unmarshal(jsonBytes, &tr.ansiOptions.Styles)
}
tr.ansiOptions.Styles = *styles tr.ansiOptions.Styles = *styles
return nil return nil
default:
return err
}
} }
} }