diff --git a/glamour.go b/glamour.go index da31d47..8cb7b7c 100644 --- a/glamour.go +++ b/glamour.go @@ -18,6 +18,17 @@ import ( "github.com/charmbracelet/glamour/ansi" ) +// Default styles. +const ( + AsciiStyle = "ascii" + AutoStyle = "auto" + DarkStyle = "dark" + DraculaStyle = "dracula" + LightStyle = "light" + NoTTYStyle = "notty" + PinkStyle = "pink" +) + // A TermRendererOption sets an option on a TermRenderer. type TermRendererOption func(*TermRenderer) error @@ -122,7 +133,7 @@ func WithStandardStyle(style string) TermRendererOption { // WithAutoStyle sets a TermRenderer's styles with either the standard dark // or light style, depending on the terminal's background color at run-time. func WithAutoStyle() TermRendererOption { - return WithStandardStyle("auto") + return WithStandardStyle(AutoStyle) } // WithEnvironmentConfig sets a TermRenderer's styles based on the @@ -237,14 +248,14 @@ func (tr *TermRenderer) RenderBytes(in []byte) ([]byte, error) { func getEnvironmentStyle() string { glamourStyle := os.Getenv("GLAMOUR_STYLE") if len(glamourStyle) == 0 { - glamourStyle = "auto" + glamourStyle = AutoStyle } return glamourStyle } func getDefaultStyle(style string) (*ansi.StyleConfig, error) { - if style == "auto" { + if style == AutoStyle { if termenv.HasDarkBackground() { return &DarkStyleConfig, nil } diff --git a/glamour_test.go b/glamour_test.go index 8ff127f..15f7ccd 100644 --- a/glamour_test.go +++ b/glamour_test.go @@ -15,7 +15,7 @@ const ( func TestTermRendererWriter(t *testing.T) { r, err := NewTermRenderer( - WithStandardStyle("dark"), + WithStandardStyle(DarkStyle), ) if err != nil { t.Fatal(err) @@ -152,7 +152,7 @@ func TestStyles(t *testing.T) { } _, err = NewTermRenderer( - WithStandardStyle("auto"), + WithStandardStyle(AutoStyle), ) if err != nil { t.Fatal(err) diff --git a/styles.go b/styles.go index 49c7b05..e904dfd 100644 --- a/styles.go +++ b/styles.go @@ -759,12 +759,12 @@ var ( // DefaultStyles are the default styles. DefaultStyles = map[string]*ansi.StyleConfig{ - "ascii": &ASCIIStyleConfig, - "dark": &DarkStyleConfig, - "light": &LightStyleConfig, - "pink": &PinkStyleConfig, - "notty": &NoTTYStyleConfig, - "dracula": &DraculaStyleConfig, + AsciiStyle: &ASCIIStyleConfig, + DarkStyle: &DarkStyleConfig, + DraculaStyle: &DraculaStyleConfig, + LightStyle: &LightStyleConfig, + NoTTYStyle: &NoTTYStyleConfig, + PinkStyle: &PinkStyleConfig, } ) diff --git a/testdata/fuzz/fuzz.go b/testdata/fuzz/fuzz.go index bb3c588..9410b85 100644 --- a/testdata/fuzz/fuzz.go +++ b/testdata/fuzz/fuzz.go @@ -3,7 +3,7 @@ package fuzzing import "github.com/charmbracelet/glamour" func Fuzz(data []byte) int { - _, err := glamour.RenderBytes(data, "dark") + _, err := glamour.RenderBytes(data, glamour.DarkStyle) if err != nil { return 0 }