mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 00:47:15 -04:00
feat: use (exported) consts for default styles (#232)
This commit is contained in:
+14
-3
@@ -18,6 +18,17 @@ import (
|
|||||||
"github.com/charmbracelet/glamour/ansi"
|
"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.
|
// A TermRendererOption sets an option on a TermRenderer.
|
||||||
type TermRendererOption func(*TermRenderer) error
|
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
|
// WithAutoStyle sets a TermRenderer's styles with either the standard dark
|
||||||
// or light style, depending on the terminal's background color at run-time.
|
// or light style, depending on the terminal's background color at run-time.
|
||||||
func WithAutoStyle() TermRendererOption {
|
func WithAutoStyle() TermRendererOption {
|
||||||
return WithStandardStyle("auto")
|
return WithStandardStyle(AutoStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithEnvironmentConfig sets a TermRenderer's styles based on the
|
// WithEnvironmentConfig sets a TermRenderer's styles based on the
|
||||||
@@ -237,14 +248,14 @@ func (tr *TermRenderer) RenderBytes(in []byte) ([]byte, error) {
|
|||||||
func getEnvironmentStyle() string {
|
func getEnvironmentStyle() string {
|
||||||
glamourStyle := os.Getenv("GLAMOUR_STYLE")
|
glamourStyle := os.Getenv("GLAMOUR_STYLE")
|
||||||
if len(glamourStyle) == 0 {
|
if len(glamourStyle) == 0 {
|
||||||
glamourStyle = "auto"
|
glamourStyle = AutoStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
return glamourStyle
|
return glamourStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultStyle(style string) (*ansi.StyleConfig, error) {
|
func getDefaultStyle(style string) (*ansi.StyleConfig, error) {
|
||||||
if style == "auto" {
|
if style == AutoStyle {
|
||||||
if termenv.HasDarkBackground() {
|
if termenv.HasDarkBackground() {
|
||||||
return &DarkStyleConfig, nil
|
return &DarkStyleConfig, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ const (
|
|||||||
|
|
||||||
func TestTermRendererWriter(t *testing.T) {
|
func TestTermRendererWriter(t *testing.T) {
|
||||||
r, err := NewTermRenderer(
|
r, err := NewTermRenderer(
|
||||||
WithStandardStyle("dark"),
|
WithStandardStyle(DarkStyle),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -152,7 +152,7 @@ func TestStyles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = NewTermRenderer(
|
_, err = NewTermRenderer(
|
||||||
WithStandardStyle("auto"),
|
WithStandardStyle(AutoStyle),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -759,12 +759,12 @@ var (
|
|||||||
|
|
||||||
// DefaultStyles are the default styles.
|
// DefaultStyles are the default styles.
|
||||||
DefaultStyles = map[string]*ansi.StyleConfig{
|
DefaultStyles = map[string]*ansi.StyleConfig{
|
||||||
"ascii": &ASCIIStyleConfig,
|
AsciiStyle: &ASCIIStyleConfig,
|
||||||
"dark": &DarkStyleConfig,
|
DarkStyle: &DarkStyleConfig,
|
||||||
"light": &LightStyleConfig,
|
DraculaStyle: &DraculaStyleConfig,
|
||||||
"pink": &PinkStyleConfig,
|
LightStyle: &LightStyleConfig,
|
||||||
"notty": &NoTTYStyleConfig,
|
NoTTYStyle: &NoTTYStyleConfig,
|
||||||
"dracula": &DraculaStyleConfig,
|
PinkStyle: &PinkStyleConfig,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3,7 +3,7 @@ package fuzzing
|
|||||||
import "github.com/charmbracelet/glamour"
|
import "github.com/charmbracelet/glamour"
|
||||||
|
|
||||||
func Fuzz(data []byte) int {
|
func Fuzz(data []byte) int {
|
||||||
_, err := glamour.RenderBytes(data, "dark")
|
_, err := glamour.RenderBytes(data, glamour.DarkStyle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user