mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-05 16:37:19 -04:00
Support 'auto' style to make it accessible by the Render(Bytes) helper function
This commit is contained in:
+8
-9
@@ -114,15 +114,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 func(tr *TermRenderer) error {
|
return WithStandardStyle("auto")
|
||||||
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
|
||||||
@@ -216,6 +208,13 @@ func (tr *TermRenderer) RenderBytes(in []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultStyle(style string) (*ansi.StyleConfig, error) {
|
func getDefaultStyle(style string) (*ansi.StyleConfig, error) {
|
||||||
|
if style == "auto" {
|
||||||
|
if termenv.HasDarkBackground() {
|
||||||
|
return &DarkStyleConfig, nil
|
||||||
|
}
|
||||||
|
return &LightStyleConfig, nil
|
||||||
|
}
|
||||||
|
|
||||||
styles, ok := DefaultStyles[style]
|
styles, ok := DefaultStyles[style]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("%s: style not found", style)
|
return nil, fmt.Errorf("%s: style not found", style)
|
||||||
|
|||||||
@@ -97,6 +97,13 @@ func TestStyles(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = NewTermRenderer(
|
||||||
|
WithStandardStyle("auto"),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRenderHelpers(t *testing.T) {
|
func TestRenderHelpers(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user