Documentation
¶
Overview ¶
Package theme parses Monaco-format editor themes (IStandaloneThemeData: {base, inherit, rules, colors}) and resolves Monarch token types such as "keyword.go" or "string.escape.ts" to display styles.
Token resolution follows Monaco's TokenTheme: rules form a trie keyed by dot-separated segments and a token takes the style of the deepest matching node. A node starts as a copy of its parent's style when it is created and each rule only overwrites the fields it sets, so a rule that omits foreground, background or fontStyle inherits them from its nearest ancestor rule, while fontStyle "" explicitly resets to plain.
Parsing is lenient about individual values, unlike Monaco in places: an invalid color in the colors table (Monaco shows it as red) or in a rule (Monaco throws and the theme fails to apply) is ignored and recorded in Theme.Warnings; non-string rule fields are ignored field by field (as Monaco's typeof checks do) and non-object rules are skipped. Only malformed JSON or a missing/unknown base fails Parse.
The structure follows Monaco's TokenTheme (vs/editor/common/languages/ supports/tokenization.ts) and StandaloneTheme (vs/editor/standalone/browser/ standaloneThemeService.ts), Copyright (c) Microsoft Corporation, MIT License. See NOTICE in this directory.
Experimental: this package's API may change in any 0.x release (see docs/release.md, "API 稳定性").
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Style ¶
type Style struct {
Foreground, Background color.NRGBA
Bold, Italic, Underline, Strikethrough bool
}
Style is the resolved display style of a token type.
type Theme ¶
type Theme struct {
// contains filtered or unexported fields
}
Theme is a parsed, immutable editor theme. It is safe for concurrent use.
func Base ¶
Base returns Monaco's built-in base theme "vs", "vs-dark", "hc-black" or "hc-light", or nil for any other name. The result is shared.
func Parse ¶
Parse parses a Monaco theme. "base" must be one of the four base themes; when "inherit" is true the base theme's rules are applied first and its colors fill in keys the theme does not define. Colors are hex RGB, RGBA, RRGGBB or RRGGBBAA with an optional leading '#'; token rule colors are opaque, so any alpha digits in them are ignored, as in Monaco. Invalid individual values are ignored and reported by Warnings (see the package doc).
func (*Theme) BaseName ¶
BaseName returns the theme's base: "vs", "vs-dark", "hc-black" or "hc-light" (the theme type that selects default colors).
func (*Theme) Color ¶
Color returns the theme color for a workbench color key such as "editor.lineHighlightBackground": the theme's own value (with inherit, its base theme's values for keys it does not set), else Monaco 0.56's registered default for the theme's base type, resolved against the theme's colors (colors.go). It reports false for a key without a color: one Monaco has no default for there (editor.lineHighlightBackground), or that is not a registered color id.
func (*Theme) OwnColor ¶
OwnColor returns the theme's own value of key (with inherit, including its base theme's colors), without the registry defaults: Monaco's theme.defines(key) is whether it reports true.