Added 'auto' style config

AutoStyleConfig points to either DarkStyleConfig or LightStyleConfig
depending on the current terminal's background color.
This commit is contained in:
Christian Muehlhaeuser
2020-01-14 02:01:22 +01:00
parent 392f5b033b
commit ac879be81a
5 changed files with 28 additions and 4 deletions
+1 -1
View File
@@ -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 {
+9
View File
@@ -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 {
+1 -1
View File
@@ -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
)
+2 -2
View File
@@ -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=
+15
View File
@@ -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
}