Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColorScheme ¶
type ColorScheme struct {
// Name is the name of the color scheme.
Name string
color.ColorPalette
// contains filtered or unexported fields
}
ColorScheme defines the token types and their styles used for syntax highlighting.
func (*ColorScheme) AddStyle ¶
func (cs *ColorScheme) AddStyle(scope StyleScope, textStyle TextStyle, fg, bg color.Color)
func (*ColorScheme) GetStyleByID ¶
func (cs *ColorScheme) GetStyleByID(scopeID int) StyleMeta
func (*ColorScheme) GetTokenStyle ¶
func (cs *ColorScheme) GetTokenStyle(scope StyleScope) StyleMeta
GetTokenStyle finds a proper StyleMeta for the requested scope. When the scope has no registered style, search upwards using the parent scope. If everything has tried but still failed, it returns an empty style.
func (*ColorScheme) Scopes ¶
func (cs *ColorScheme) Scopes() []StyleScope
Scopes returns all the registered style scopes.
type StyleMeta ¶
type StyleMeta uint32
StyleMeta applies a bit packed binary format to encode tokens from syntax lexer, to be used as styles for text rendering. This is like TokenMetadata in Monaco/vscode.
It uses 4 bytes to hold the metadata, and the layout is as follows: Bits: 31 ... 0 [3][7][8][8][6] = 32 | | | | | | | | | └── Text style flags (6bits, bold, italic, underline, Squiggle, strikethrough, border) | | | └───── Background color ID (8bits, 0–255) | | └──────── Foreground color ID (8bits, 0–255) | └─────────── Token type (7bits, 0–127) └────────────── reserved bits (3bits)
The color IDs are mapped to indices of color palette.
func (StyleMeta) Background ¶
func (StyleMeta) Foreground ¶
type StyleScope ¶
type StyleScope string
StyleScope is a TextMate style scope notation, eg, 'keyword.control.if', 'entity.name.function'
func (StyleScope) IsChild ¶
func (s StyleScope) IsChild(other StyleScope) bool
IsChild checks if other is a sub scope of s.
func (StyleScope) IsValid ¶
func (s StyleScope) IsValid() bool
IsValid checks if s has a valid notation.
func (StyleScope) Parent ¶
func (s StyleScope) Parent() StyleScope
Parent returns the parent of scope s. If s is invalid, it returns an invalid empty scope.
type TextTokens ¶
type TextTokens struct {
// contains filtered or unexported fields
}
func NewTextTokens ¶
func NewTextTokens(scheme *ColorScheme) *TextTokens
func (*TextTokens) QueryRange ¶
func (t *TextTokens) QueryRange(start, end int) []TokenStyle
Query tokens for rune range. start and end are in runes. start is inclusive and end is exclusive. This method assumes the tokens are sorted by start or end in ascending order.
func (*TextTokens) Set ¶
func (t *TextTokens) Set(tokens ...Token)
Set adds all the tokens, replacing the existing ones. Caller should insures the tokens are sorted by the range in ascending order .
type Token ¶
type Token struct {
// offset of the start rune in the document.
Start, End int
// Scope registered in the color scheme.
Scope StyleScope
}