feat: use (exported) consts for default styles (#232)

This commit is contained in:
Christian Rocha
2023-05-19 09:14:05 -04:00
committed by GitHub
parent cd217b9c0f
commit 7528eaad66
4 changed files with 23 additions and 12 deletions
+14 -3
View File
@@ -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
}