mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 00:47:15 -04:00
Read default styles before reading from the file system (#73)
This commit is contained in:
+5
-8
@@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user