1package common
2
3import (
4 "github.com/charmbracelet/glamour"
5 gansi "github.com/charmbracelet/glamour/ansi"
6 "github.com/muesli/termenv"
7)
8
9var (
10 // DefaultColorProfile is the default color profile used by the SSH server.
11 DefaultColorProfile = termenv.ANSI256
12)
13
14func strptr(s string) *string {
15 return &s
16}
17
18// StyleConfig returns the default Glamour style configuration.
19func StyleConfig() gansi.StyleConfig {
20 noColor := strptr("")
21 s := glamour.DarkStyleConfig
22 s.H1.BackgroundColor = noColor
23 s.H1.Prefix = "# "
24 s.H1.Suffix = ""
25 s.H1.Color = strptr("39")
26 s.Document.StylePrimitive.Color = noColor
27 s.CodeBlock.Chroma.Text.Color = noColor
28 s.CodeBlock.Chroma.Name.Color = noColor
29 // This fixes an issue with the default style config. For example
30 // highlighting empty spaces with red in Dockerfile type.
31 s.CodeBlock.Chroma.Error.BackgroundColor = noColor
32 return s
33}
34
35// StyleRenderer returns a new Glamour renderer with the DefaultColorProfile.
36func StyleRenderer() gansi.RenderContext {
37 return StyleRendererWithStyles(StyleConfig())
38}
39
40// StyleRendererWithStyles returns a new Glamour renderer with the
41// DefaultColorProfile and styles.
42func StyleRendererWithStyles(styles gansi.StyleConfig) gansi.RenderContext {
43 return gansi.NewRenderContext(gansi.Options{
44 ColorProfile: DefaultColorProfile,
45 Styles: styles,
46 })
47}