diff --git a/ansi/baseelement.go b/ansi/baseelement.go index a7227cc..4548484 100644 --- a/ansi/baseelement.go +++ b/ansi/baseelement.go @@ -36,7 +36,7 @@ func renderText(w io.Writer, rules StylePrimitive, s string) { return } - p := termenv.SupportedColorProfile() + p := termenv.ColorProfile() out := termenv.String(s) if rules.Color != nil { diff --git a/glamour_test.go b/glamour_test.go index 7403f4c..f3ce372 100644 --- a/glamour_test.go +++ b/glamour_test.go @@ -90,6 +90,15 @@ func TestTermRenderer(t *testing.T) { } } +func TestStyles(t *testing.T) { + _, err := NewTermRenderer( + WithStandardStyle("auto"), + ) + if err != nil { + t.Fatal(err) + } +} + func TestRenderHelpers(t *testing.T) { in, err := ioutil.ReadFile(markdown) if err != nil { diff --git a/go.mod b/go.mod index b22de57..79ff2db 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/alecthomas/chroma v0.7.0 github.com/microcosm-cc/bluemonday v1.0.2 github.com/muesli/reflow v0.0.0-20191216070243-e5efeac4e302 - github.com/muesli/termenv v0.0.0-20200113040742-787d65c2d855 + github.com/muesli/termenv v0.0.0-20200114005430-a7aeffd54956 github.com/olekukonko/tablewriter v0.0.4 github.com/yuin/goldmark v1.1.19 ) diff --git a/go.sum b/go.sum index 357aca8..7686771 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/le github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/muesli/reflow v0.0.0-20191216070243-e5efeac4e302 h1:jOh3Kh03uOFkRPV3PI4Am5tqACv2aELgbPgr7YgNX00= github.com/muesli/reflow v0.0.0-20191216070243-e5efeac4e302/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I= -github.com/muesli/termenv v0.0.0-20200113040742-787d65c2d855 h1:9LXLBqvMQNRbUDWEvv16RF31WtWbO3S6ZA6Wrt+gBak= -github.com/muesli/termenv v0.0.0-20200113040742-787d65c2d855/go.mod h1:QAW21ZWi5eDIAoYsevV52sibdVVCl44P+TvI0C0VKEU= +github.com/muesli/termenv v0.0.0-20200114005430-a7aeffd54956 h1:OZIYilqRi/+iIIY/9SfuRpZIujheG5Stml2tI1PpAkM= +github.com/muesli/termenv v0.0.0-20200114005430-a7aeffd54956/go.mod h1:QAW21ZWi5eDIAoYsevV52sibdVVCl44P+TvI0C0VKEU= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8= github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= diff --git a/styles.go b/styles.go index 12640ee..ffc29ad 100644 --- a/styles.go +++ b/styles.go @@ -3,10 +3,16 @@ package glamour //go:generate go run ./internal/generate-style-json import ( + "github.com/muesli/termenv" + "github.com/charmbracelet/glamour/ansi" ) var ( + // AutoStyleConfig is either pointing to DarkStyleConfig or LightStyleConfig + // depending on the background color of the terminal glamour is run in + AutoStyleConfig *ansi.StyleConfig + // ASCIIStyleConfig uses only ASCII characters. ASCIIStyleConfig = ansi.StyleConfig{ Document: ansi.StyleBlock{ @@ -658,3 +664,12 @@ var ( func boolPtr(b bool) *bool { return &b } func stringPtr(s string) *string { return &s } func uintPtr(u uint) *uint { return &u } + +func init() { + AutoStyleConfig = &LightStyleConfig + if termenv.HasDarkBackground() { + AutoStyleConfig = &DarkStyleConfig + } + + DefaultStyles["auto"] = AutoStyleConfig +}