styles

package
v0.0.0-...-55b6186 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Table chroma.TokenType = 9000 + iota
	TableHeader
	TableRow
	TableRowAlt

	StrongEmph
	CodeSpan
)

Variables

View Source
var (
	GlamourDark       = ChromaStyleFromConfig("glamour-dark", glamourstyles.DarkStyleConfig)
	GlamourLight      = ChromaStyleFromConfig("glamour-light", glamourstyles.LightStyleConfig)
	GlamourDracula    = ChromaStyleFromConfig("glamour-dracula", glamourstyles.DraculaStyleConfig)
	GlamourTokyoNight = ChromaStyleFromConfig("glamour-tokyo-night", glamourstyles.TokyoNightStyleConfig)
	GlamourPink       = ChromaStyleFromConfig("glamour-pink", glamourstyles.PinkStyleConfig)
)

Glamour themes converted from github.com/charmbracelet/glamour/styles.

View Source
var Pulumi = styles.Register(chroma.MustNewStyle("pulumi", chroma.StyleEntries{
	chroma.Text:                "#d7d7d7",
	chroma.Error:               "#d75f5f",
	chroma.Comment:             "#afafaf",
	chroma.Keyword:             "#af87af",
	chroma.Operator:            "#5fafd7",
	chroma.Punctuation:         "#d7afff",
	chroma.Name:                "#d7d7d7",
	chroma.NameAttribute:       "#d7d7d7",
	chroma.NameClass:           "#d7d7d7",
	chroma.NameConstant:        "#d7d7d7",
	chroma.NameDecorator:       "#d7d7d7",
	chroma.NameException:       "#d7d7d7",
	chroma.NameFunction:        "#d7d7d7",
	chroma.NameOther:           "#d7d7d7",
	chroma.NameTag:             "#d7d7d7",
	chroma.LiteralNumber:       "#87ffaf",
	chroma.Literal:             "#00d7af",
	chroma.LiteralDate:         "#00d7af",
	chroma.LiteralString:       "#ffaf5f",
	chroma.LiteralStringEscape: "#5f5f87",
	chroma.GenericDeleted:      "#d75f5f",
	chroma.GenericEmph:         "italic",
	chroma.GenericHeading:      "#d787af bold",
	chroma.GenericInserted:     "#5f875f",
	chroma.GenericStrong:       "bold",
	StrongEmph:                 "bold italic",
	chroma.GenericSubheading:   "#d787af",
	chroma.GenericUnderline:    "underline",
	CodeSpan:                   "#d7d7d7 bg:#303030",
	Table:                      "bg:#121212",
	TableHeader:                "#d787af",
	TableRowAlt:                "bg:#323232",
}))

Functions

func AutoTheme

func AutoTheme() *chroma.Style

AutoTheme returns GlamourDark or GlamourLight depending on the terminal's background color. It queries stdin/stdout to detect whether the terminal has a dark background, matching the behavior of glamour's "auto" style.

func ChromaStyleFromConfig

func ChromaStyleFromConfig(name string, cfg ansi.StyleConfig) *chroma.Style

ChromaStyleFromConfig converts a glamour ansi.StyleConfig into a *chroma.Style registered under the given name. This produces the same format used by the renderer's WithTheme option.

Types

type StyleEntry

type StyleEntry struct {
	Colour     color.Color
	Background color.Color
	Bold       Trilean
	Italic     Trilean
	Underline  Trilean
}

StyleEntry defines the visual style for a single token type.

func (StyleEntry) IsZero

func (e StyleEntry) IsZero() bool

IsZero returns true if all fields are at their zero/nil/Pass values.

type Theme

type Theme struct {
	// contains filtered or unexported fields
}

Theme maps token types to style entries.

func FromStyleConfig

func FromStyleConfig(cfg ansi.StyleConfig) *Theme

FromStyleConfig converts a glamour ansi.StyleConfig into a *Theme.

Chroma syntax-highlighting entries are applied first (lower priority), then structural markdown fields are overlaid on top.

func NewTheme

func NewTheme(entries map[TokenType]StyleEntry) *Theme

NewTheme creates a new Theme from a map of token types to style entries.

func (*Theme) Get

func (t *Theme) Get(token TokenType) StyleEntry

Get returns the style entry for the given token type, inheriting from parent token types (sub-category, category, Text, Background) as needed. This matches chroma's Style.Get behavior.

type TokenType

type TokenType int

TokenType identifies a syntactic element for styling purposes. Values match chroma.TokenType so that a simple cast converts between them.

const (
	Background TokenType = -1
	Error      TokenType = -7
	EOFType    TokenType = 0
)

Meta token types.

const (
	Keyword TokenType = 1000 + iota
	KeywordConstant
	KeywordDeclaration
	KeywordNamespace
	KeywordPseudo
	KeywordReserved
	KeywordType
)

Keywords.

const (
	Name TokenType = 2000 + iota
	NameAttribute
	NameBuiltin
	NameBuiltinPseudo
	NameClass
	NameConstant
	NameDecorator
	NameEntity
	NameException
	NameFunction
	NameFunctionMagic
	NameKeyword
	NameLabel
	NameNamespace
	NameOperator
	NameOther
	NamePseudo
	NameProperty
	NameTag
)

Names.

const (
	Literal TokenType = 3000 + iota
	LiteralDate
)

Literals.

const (
	LiteralString TokenType = 3100 + iota
	LiteralStringAffix
	LiteralStringAtom
	LiteralStringBacktick
	LiteralStringBoolean
	LiteralStringChar
	LiteralStringDelimiter
	LiteralStringDoc
	LiteralStringDouble
	LiteralStringEscape
	LiteralStringHeredoc
)

Strings.

const (
	Generic TokenType = 7000 + iota
	GenericDeleted
	GenericEmph
	GenericError
	GenericHeading
	GenericInserted
	GenericOutput
	GenericPrompt
	GenericStrong
	GenericSubheading
	GenericTraceback
	GenericUnderline
)

Generic tokens.

const (
	Comment TokenType = 6000 + iota
)

Comments.

const (
	LiteralNumber TokenType = 3200 + iota
)

Numbers.

const (
	Operator TokenType = 4000 + iota
)

Operators.

const (
	Punctuation TokenType = 5000 + iota
)

Punctuation.

const (
	Text TokenType = 8000 + iota
)

Text.

type Trilean

type Trilean uint8

Trilean is a tri-state boolean: Yes, No, or Pass (inherit).

const (
	Pass Trilean = iota
	Yes
	No
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL