mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-05 16:37:19 -04:00
Don't determine auto style on init
The automatic style configuration will now only be determined, when initialized with the WithAutoStyle renderer option.
This commit is contained in:
+14
@@ -111,6 +111,20 @@ 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 func(tr *TermRenderer) error {
|
||||||
|
style := LightStyleConfig
|
||||||
|
if termenv.HasDarkBackground() {
|
||||||
|
style = DarkStyleConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
tr.ansiOptions.Styles = style
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithStylePath sets a TermRenderer's style from stylePath. stylePath is first
|
// WithStylePath sets a TermRenderer's style from stylePath. stylePath is first
|
||||||
// interpreted as a filename. If no such file exists, it is re-interpreted as a
|
// interpreted as a filename. If no such file exists, it is re-interpreted as a
|
||||||
// standard style.
|
// standard style.
|
||||||
|
|||||||
+1
-1
@@ -92,7 +92,7 @@ func TestTermRenderer(t *testing.T) {
|
|||||||
|
|
||||||
func TestStyles(t *testing.T) {
|
func TestStyles(t *testing.T) {
|
||||||
_, err := NewTermRenderer(
|
_, err := NewTermRenderer(
|
||||||
WithStandardStyle("auto"),
|
WithAutoStyle(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -3,16 +3,10 @@ package glamour
|
|||||||
//go:generate go run ./internal/generate-style-json
|
//go:generate go run ./internal/generate-style-json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/muesli/termenv"
|
|
||||||
|
|
||||||
"github.com/charmbracelet/glamour/ansi"
|
"github.com/charmbracelet/glamour/ansi"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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 uses only ASCII characters.
|
||||||
ASCIIStyleConfig = ansi.StyleConfig{
|
ASCIIStyleConfig = ansi.StyleConfig{
|
||||||
Document: ansi.StyleBlock{
|
Document: ansi.StyleBlock{
|
||||||
@@ -664,12 +658,3 @@ var (
|
|||||||
func boolPtr(b bool) *bool { return &b }
|
func boolPtr(b bool) *bool { return &b }
|
||||||
func stringPtr(s string) *string { return &s }
|
func stringPtr(s string) *string { return &s }
|
||||||
func uintPtr(u uint) *uint { return &u }
|
func uintPtr(u uint) *uint { return &u }
|
||||||
|
|
||||||
func init() {
|
|
||||||
AutoStyleConfig = &LightStyleConfig
|
|
||||||
if termenv.HasDarkBackground() {
|
|
||||||
AutoStyleConfig = &DarkStyleConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
DefaultStyles["auto"] = AutoStyleConfig
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user