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
+7 -10
View File
@@ -135,20 +135,17 @@ func WithEnvironmentConfig() TermRendererOption {
// standard style.
func WithStylePath(stylePath string) TermRendererOption {
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 {
return err
}
tr.ansiOptions.Styles = *styles
return nil
default:
return err
return json.Unmarshal(jsonBytes, &tr.ansiOptions.Styles)
}
tr.ansiOptions.Styles = *styles
return nil
}
}