Documentation
¶
Overview ¶
Package theme holds color themes, token colors and the workbench color registry (SPEC §8.4).
Index ¶
- Constants
- Variables
- func PickDescription(info Info) string
- func TerminalANSIColorIDs() [16]string
- type Color
- func (c Color) ARGB() uint32
- func (c Color) Blend(background Color) Color
- func (c Color) Darken(factor float64) Color
- func (c Color) Equal(o Color) bool
- func (c Color) Hex() string
- func (c Color) IsDarkerThan(o Color) bool
- func (c Color) IsLighterThan(o Color) bool
- func (c Color) IsOpaque() bool
- func (c Color) Lighten(factor float64) Color
- func (c Color) MakeOpaque(background Color) Color
- func (c Color) Mix(other Color, factor float64) Color
- func (c Color) RGBA() (r, g, b int, a float64)
- func (c Color) RelativeLuminance() float64
- func (c Color) String() string
- func (c Color) WithAlphaFactor(factor float64) Color
- type ColorContribution
- type ColorDefaults
- type ColorEnv
- type ColorMap
- type ColorRegistry
- type ColorTheme
- type ColorValue
- func Darken(v ColorValue, factor float64) ColorValue
- func Hex(s string) ColorValue
- func IfDefinedThenElse(id string, then, otherwise ColorValue) ColorValue
- func LessProminent(v, background ColorValue, factor, transparency float64) ColorValue
- func Lighten(v ColorValue, factor float64) ColorValue
- func Lit(c Color) ColorValue
- func Mix(v, with ColorValue, ratio float64) ColorValue
- func OneOf(values ...ColorValue) ColorValue
- func Opaque(v, background ColorValue) ColorValue
- func Ref(id string) ColorValue
- func Transparent(v ColorValue, factor float64) ColorValue
- type FileIcon
- type FileIconChoice
- type FileIconKind
- type FileIconQuery
- type FileIconTheme
- type FontStyle
- type Info
- type PickerEntry
- type PickerGroup
- type RawRule
- type Rule
- type RuleSettings
- type Scope
- type SemanticStyle
- type SemanticTheme
- type Service
- func (s *Service) Apply(settings Settings) error
- func (s *Service) Current() *ColorTheme
- func (s *Service) CurrentInfo() Info
- func (s *Service) EndPreview() error
- func (s *Service) OnChange(fn func(*ColorTheme)) (unsubscribe func())
- func (s *Service) PickerGroups() ([]PickerGroup, error)
- func (s *Service) Preview(name string) error
- func (s *Service) Previewing() bool
- func (s *Service) Registry() *ColorRegistry
- func (s *Service) SetPlatformBrightness(dark bool) error
- func (s *Service) SetUserThemes(themes []UserTheme) error
- func (s *Service) Themes() ([]Info, error)
- type Settings
- type Style
- type Theme
- type TokenTheme
- func (t *TokenTheme) Color(id int) string
- func (t *TokenTheme) Colors() []string
- func (t *TokenTheme) Defaults() Style
- func (t *TokenTheme) Match(scopes []string) (style Style, ok bool)
- func (t *TokenTheme) MatchStack(scopes *textmate.ScopeStack) (Style, bool)
- func (t *TokenTheme) Resolve(scopes []string) Style
- func (t *TokenTheme) ResolveStack(scopes *textmate.ScopeStack) Style
- func (t *TokenTheme) Semantic() *SemanticTheme
- type Type
- type UserTheme
Constants ¶
const ( // DefaultDark is the default theme. DefaultDark = "Dark Modern" // DefaultLight is the default theme of a light desktop (window.autoDetectColorScheme). DefaultLight = "Light Modern" )
DefaultDark and DefaultLight are the names of the themes that are used when no theme is chosen.
const ( // PickLightThemes is the title of the group of the light themes. PickLightThemes = "light themes" // PickDarkThemes is the title of the group of the dark themes. PickDarkThemes = "dark themes" // PickHighContrastThemes is the title of the group of the high contrast themes. PickHighContrastThemes = "high contrast themes" // PickFileIconThemes is the title of the group of the file icon theme picker. PickFileIconThemes = "file icon themes" )
Titles of the groups of the color theme picker.
const DefaultFileIconTheme = "vs-seti"
DefaultFileIconTheme is the id of the file icon theme that is used when the setting does not choose one: VS Code's Seti.
Variables ¶
var ( // ColorWhite is #ffffff. ColorWhite = NewColor(255, 255, 255, 1) // ColorBlack is #000000. ColorBlack = NewColor(0, 0, 0, 1) // ColorLightGrey is #d3d3d3. ColorLightGrey = NewColor(211, 211, 211, 1) // ColorTransparent is black with no opacity. ColorTransparent = NewColor(0, 0, 0, 0) )
The colors that VS Code names.
Functions ¶
func PickDescription ¶
PickDescription is the description of a theme in the picker (VS Code's toEntry): "Default Dark" and "Default Light" for Dark Modern and Light Modern, the id of a theme whose id is not its label (the "Default High Contrast" of Dark High Contrast), "Default " and the id for the other bundled themes, and nothing for a user theme whose label is its id.
func TerminalANSIColorIDs ¶ added in v1.0.0
func TerminalANSIColorIDs() [16]string
TerminalANSIColorIDs are the ids of the sixteen ANSI colors of the terminal, in the order of the palette.
Types ¶
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color is a color with an alpha, with the operations that workbench colors derive each other with. It follows VS Code's Color: the red, green and blue are whole numbers from 0 to 255, the alpha is rounded to three decimals, and lightening and darkening go through hue, saturation and lightness.
Ported from VS Code: src/vs/base/common/color.ts
func NewColor ¶
NewColor makes a color: red, green and blue are cut to 0..255 (the fraction is dropped), the alpha is cut to 0..1 and rounded to three decimals.
func ParseColor ¶
ParseColor reads #rgb, #rgba, #rrggbb or #rrggbbaa. A character that is not a hex digit counts as 0, as in VS Code. ok is false when the text does not start with # or has another length.
Ported from VS Code: src/vs/base/common/color.ts (Color.Format.CSS.parseHex)
func (Color) IsDarkerThan ¶
IsDarkerThan tells whether the color has a lower relative luminance than another.
func (Color) IsLighterThan ¶
IsLighterThan tells whether the color has a higher relative luminance than another.
func (Color) MakeOpaque ¶
MakeOpaque gives the opaque color that looks like this one over an opaque background.
func (Color) Mix ¶
Mix mixes the color with another: a factor of 0 is this color, 1 the other, 0.5 half of each.
func (Color) RelativeLuminance ¶
RelativeLuminance is the WCAG relative luminance, from 0 (black) to 1 (white).
func (Color) String ¶
String writes the color as VS Code does: #rrggbb when it is opaque, else rgba(r, g, b, a).
func (Color) WithAlphaFactor ¶
WithAlphaFactor multiplies the alpha by the factor; VS Code calls it transparent().
type ColorContribution ¶
type ColorContribution struct {
// ID is the color's id in a theme's "colors": "editor.background".
ID string
// Description says what the color paints.
Description string
// Defaults are the colors of a theme that does not set it.
Defaults ColorDefaults
// NeedsTransparency says that the color must not be opaque, as it is painted over what it
// marks (a selection).
NeedsTransparency bool
// DeprecationMessage is set for an id that a newer one replaces.
DeprecationMessage string
}
ColorContribution is a workbench color that the registry knows.
type ColorDefaults ¶
type ColorDefaults struct {
Dark, Light, HCDark, HCLight ColorValue
}
ColorDefaults are the defaults of a workbench color for each theme type. A nil value is no default: the color is not painted unless the theme sets it.
func AllThemes ¶
func AllThemes(v ColorValue) ColorDefaults
AllThemes are the same default for every theme type.
type ColorEnv ¶
type ColorEnv interface {
// Color gives the color with an id in the theme: the one the theme sets, else its default.
Color(id string) (Color, bool)
// Defines tells whether the theme itself sets the color.
Defines(id string) bool
}
ColorEnv is what a derived color asks of the theme it is resolved in.
type ColorMap ¶
type ColorMap struct {
// contains filtered or unexported fields
}
ColorMap numbers the colors of a theme. Id 0 is no color; the colors are kept in upper case.
Ported from vscode-textmate: src/theme.ts (ColorMap)
func (*ColorMap) Color ¶
Color gives the color with a number, or "" for 0 or a number that is not used.
type ColorRegistry ¶
type ColorRegistry struct {
// contains filtered or unexported fields
}
ColorRegistry holds the workbench colors with their defaults (SPEC §8.4). Each step that first paints a color registers it here, with the values of VS Code.
Ported from VS Code: src/vs/platform/theme/common/colorUtils.ts (ColorRegistry)
func DefaultColorRegistry ¶
func DefaultColorRegistry() *ColorRegistry
DefaultColorRegistry makes a registry with the workbench colors Emetos paints. Each step that first paints a color adds it here (or to a function it calls), with the id, description and defaults of VS Code.
func NewColorRegistry ¶
func NewColorRegistry() *ColorRegistry
NewColorRegistry makes an empty registry.
func (*ColorRegistry) Colors ¶
func (r *ColorRegistry) Colors() []ColorContribution
Colors lists the registered colors by id.
func (*ColorRegistry) Lookup ¶
func (r *ColorRegistry) Lookup(id string) (ColorContribution, bool)
Lookup gives the color with an id.
func (*ColorRegistry) MustRegister ¶
func (r *ColorRegistry) MustRegister(colors ...ColorContribution)
MustRegister is Register for the colors of the program, whose registration cannot fail unless the list has a mistake; it panics with the error.
func (*ColorRegistry) Register ¶
func (r *ColorRegistry) Register(c ColorContribution) error
Register adds a color. The error has the tag ColorInvalid when the id is empty and ColorAlreadyRegistered when it is taken.
type ColorTheme ¶
type ColorTheme struct {
// contains filtered or unexported fields
}
ColorTheme is a theme with the registry its colors default from: it gives the workbench color of any id, from what the theme sets or else from the default of the registry for the type of the theme.
Ported from VS Code: src/vs/workbench/services/themes/common/colorThemeData.ts (getColor, getDefault)
func NewColorTheme ¶
func NewColorTheme(t *Theme, r *ColorRegistry) *ColorTheme
NewColorTheme makes the color theme of a theme. A color the theme gives in a form that is not a color is red, as VS Code reads it.
func (*ColorTheme) Color ¶
func (ct *ColorTheme) Color(id string) (Color, bool)
Color gives the color with an id: the one the theme sets, else the default of the registry for the theme's type. ok is false when neither is a color.
func (*ColorTheme) Default ¶
func (ct *ColorTheme) Default(id string) (Color, bool)
Default gives the default color of the registry for an id in this theme.
func (*ColorTheme) Defines ¶
func (ct *ColorTheme) Defines(id string) bool
Defines tells whether the theme sets the color.
func (*ColorTheme) Theme ¶
func (ct *ColorTheme) Theme() *Theme
Theme is the theme the colors come from.
type ColorValue ¶
type ColorValue interface {
// contains filtered or unexported methods
}
ColorValue is the default of a workbench color: a color, the color of another id, or a color derived from others. A nil ColorValue is no color.
Ported from VS Code: src/vs/platform/theme/common/colorUtils.ts (ColorValue, ColorTransform)
func Darken ¶
func Darken(v ColorValue, factor float64) ColorValue
Darken is the value, darker by the factor.
func Hex ¶
func Hex(s string) ColorValue
Hex is a color value written as #rgb, #rgba, #rrggbb or #rrggbbaa. A text that is not a color is red, as VS Code's Color.fromHex has it.
func IfDefinedThenElse ¶
func IfDefinedThenElse(id string, then, otherwise ColorValue) ColorValue
IfDefinedThenElse is the then value when the theme sets the color id, else the else value.
func LessProminent ¶
func LessProminent(v, background ColorValue, factor, transparency float64) ColorValue
LessProminent is the value moved away from the background, so as to be less prominent, by the factor and made transparent by the transparency.
func Lighten ¶
func Lighten(v ColorValue, factor float64) ColorValue
Lighten is the value, lighter by the factor.
func Mix ¶
func Mix(v, with ColorValue, ratio float64) ColorValue
Mix is the value mixed with another by the ratio (0 the value, 1 the other).
func OneOf ¶
func OneOf(values ...ColorValue) ColorValue
OneOf is the first of the values that has a color.
func Opaque ¶
func Opaque(v, background ColorValue) ColorValue
Opaque is the value made opaque over a background.
func Ref ¶
func Ref(id string) ColorValue
Ref is a color value that is the color of another id in the theme.
func Transparent ¶
func Transparent(v ColorValue, factor float64) ColorValue
Transparent is the value with its alpha multiplied by factor.
type FileIcon ¶
type FileIcon struct {
// Glyph is the character of the icon font.
Glyph rune
// Family is the family of the font the glyph is in (the id of the font in the theme).
Family string
// Color is the color of the glyph when HasColor.
Color Color
// HasColor says that the theme gives the glyph a color; without one the glyph takes the color of the
// text.
HasColor bool
// Scale is the size of the glyph in the size of the text (1.5 for the "150%" of Seti).
Scale float64
}
FileIcon is the icon a theme gives to a file or a folder.
type FileIconChoice ¶
type FileIconChoice struct {
// ID is the id of the theme, "" for none.
ID string
// Label and Description are the texts of the item.
Label, Description string
}
FileIconChoice is a choice of the file icon theme picker.
func FileIconChoices ¶
func FileIconChoices() []FileIconChoice
FileIconChoices lists what the file icon theme picker offers: None (no icons) and the bundled themes.
func (FileIconChoice) SettingValue ¶
func (c FileIconChoice) SettingValue() any
SettingValue is what the setting workbench.iconTheme holds for the choice: the id, or nil (null) for none.
type FileIconKind ¶
type FileIconKind int
FileIconKind tells what an icon is for.
const ( // FileIconFile is a file. FileIconFile FileIconKind = iota // FileIconFolder is a folder. FileIconFolder // FileIconRootFolder is the folder of the window. FileIconRootFolder )
type FileIconQuery ¶
type FileIconQuery struct {
// Kind is what the icon is for.
Kind FileIconKind
// Name is the name of the file or folder, without its folder.
Name string
// Parent is the name of the folder it is in, for the names the theme gives as "folder/name"; it may
// be empty.
Parent string
// LanguageID is the language of a file; empty or "plaintext" is none.
LanguageID string
// Expanded says that a folder is open in the tree.
Expanded bool
// Type is the type of the color theme: it chooses the light and the high contrast sections.
Type Type
}
FileIconQuery says which icon to look for.
type FileIconTheme ¶
type FileIconTheme struct {
// contains filtered or unexported fields
}
FileIconTheme is a file icon theme: the mapping of a theme file, ready to answer IconFor. It never changes after it is made, so it is safe for concurrent use.
func BundledFileIconTheme ¶
func BundledFileIconTheme(id string) (*FileIconTheme, error)
BundledFileIconTheme loads the file icon theme with an id: "vs-seti" is the Seti theme that comes with Emetos. Another id fails with the tag FileIconThemeNotFound.
func ParseFileIconTheme ¶
func ParseFileIconTheme(id string, data []byte) (*FileIconTheme, error)
ParseFileIconTheme reads the file of a file icon theme (VS Code's format). The id is what the setting calls the theme. It fails with the tag FileIconThemeInvalid when the text is not a JSON object that has iconDefinitions.
func (*FileIconTheme) IconFor ¶
func (t *FileIconTheme) IconFor(q FileIconQuery) (FileIcon, bool)
IconFor chooses the icon of a file or folder, and reports false when the theme has none for it.
VS Code makes a CSS rule of every association and lets the specificity of the selectors choose, so the choice is: for a file, a file name beats an extension and an extension beats a language (an extension with more dots beats one with fewer, and a file name with more dots beats one with fewer), and the default file icon is the last; for a folder, a name beats the default, and the "expanded" rules beat the plain ones when the folder is open; a section for the type of the color theme (light, high contrast) beats the document's own rules of the same kind.
type FontStyle ¶
type FontStyle int
FontStyle is the font style of a rule or token: a set of the flags below, or FontStyleNotSet.
const ( // FontStyleNotSet is the style of a rule that does not say. FontStyleNotSet FontStyle = -1 // FontStyleNone is a rule that clears the style. FontStyleNone FontStyle = 0 // FontStyleItalic is italic text. FontStyleItalic FontStyle = 1 // FontStyleBold is bold text. FontStyleBold FontStyle = 2 // FontStyleUnderline is underlined text. FontStyleUnderline FontStyle = 4 // FontStyleStrikethrough is struck-through text. FontStyleStrikethrough FontStyle = 8 )
The font styles, with the values of vscode-textmate.
type Info ¶
type Info struct {
// ID is the id the theme has in its manifest (for a user theme, its file name without the
// extension).
ID string
// Label is the name to show: "Dark Modern", "Dark+", "Light High Contrast" ...
Label string
// Type is the type of the theme.
Type Type
// Path is the file of the theme in its file system.
Path string
// Bundled tells whether the theme comes with Emetos.
Bundled bool
}
Info describes a theme that can be loaded.
type PickerEntry ¶
type PickerEntry struct {
// Info describes the theme; its ID is the id of the item.
Info Info
// Value is what the setting workbench.colorTheme holds for the theme: its label.
Value string
// Description is the text after the label: "Default Dark" for the default dark theme, the id of the
// others when it adds something.
Description string
// Current tells that the theme is the one in use.
Current bool
}
PickerEntry is a theme in the color theme picker.
type PickerGroup ¶
type PickerGroup struct {
// Title is the text of the separator above the group.
Title string
// Entries are the themes of the group.
Entries []PickerEntry
}
PickerGroup is a group of themes under a title.
type RawRule ¶
type RawRule struct {
// Name is the name of the rule, which only people read.
Name string
// Scope is where the rule applies; no scope makes the rule a default.
Scope Scope
// Settings are what the rule sets; a rule with no settings is ignored.
Settings *RuleSettings
}
RawRule is a rule of the tokenColors of a theme as the file has it.
type Rule ¶
type Rule struct {
// Scope is the last part of the selector, such as "string" in "meta.tag string".
Scope string
// ParentScopes are the other parts of the selector, the nearest ancestor first; nil when the
// selector is only a scope. A part can be ">", for a child combinator.
ParentScopes []string
// Index is the index of the rule in the theme, which makes the later of two equal rules win.
Index int
FontStyle FontStyle
Foreground string
Background string
FontFamily string
FontSize float64
LineHeight float64
}
Rule is a rule with its scope in one selector, as ParseRules makes it.
func ParseRules ¶
ParseRules turns the rules of a theme into one rule for each selector: the selectors of a string are split at the commas (not those of a list), invalid colors are dropped and the font style is read.
Ported from vscode-textmate: src/theme.ts (parseTheme)
type RuleSettings ¶
type RuleSettings struct {
FontStyle *string
Foreground *string
Background *string
FontFamily *string
FontSize *float64
LineHeight *float64
// contains filtered or unexported fields
}
RuleSettings are the settings of a rule. A nil pointer is a setting that is not there.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope is the scope of a rule as the theme file gives it: a string of selectors separated by commas, a list of selectors, or nothing (the rule is a default).
type SemanticStyle ¶ added in v1.0.0
type SemanticStyle struct {
// Foreground is the color as "#RRGGBB" or "#RRGGBBAA", or empty for none.
Foreground string
// Set is the font styles the style says something about (FontStyleItalic and its kin), and On those of them that are on:
// {Set: Italic|Bold, On: Italic} makes italic and not bold.
Set, On FontStyle
}
SemanticStyle is the look a semantic token gives to the text it covers. A part it does not set is left as the TextMate token has it.
func (SemanticStyle) Apply ¶ added in v1.0.0
func (s SemanticStyle) Apply(base FontStyle) FontStyle
Apply is the font style of a TextMate token with this style on top: the flags the style sets are its own, the others stay.
func (SemanticStyle) IsZero ¶ added in v1.0.0
func (s SemanticStyle) IsZero() bool
IsZero says that the style says nothing.
type SemanticTheme ¶ added in v1.0.0
type SemanticTheme struct {
// Enabled is the theme's semanticHighlighting: whether it asks for semantic highlighting.
Enabled bool
// contains filtered or unexported fields
}
SemanticTheme gives the look of a semantic token in a theme. It is safe for concurrent use.
func NewSemanticTheme ¶ added in v1.0.0
func NewSemanticTheme(t *Theme, tokens *TokenTheme) *SemanticTheme
NewSemanticTheme makes the semantic theme of a theme: its semanticTokenColors, and the token theme that the defaults fall back to (the TextMate rules of the same theme). The rules of a selector the registry does not know of are kept, as VS Code keeps them.
func (*SemanticTheme) Style ¶ added in v1.0.0
func (s *SemanticTheme) Style(typ string, modifiers []string, language string) (SemanticStyle, bool)
Style gives the look of a token of a type with modifiers in a language: the rules of the theme and of the settings that fit it, the best fit for each part of the style (later rules win among equal fits); whatever they leave unsaid is taken from the TextMate rules of the theme through the registry's defaults. ok is false when nothing says anything.
Ported from VS Code: colorThemeData.ts (getTokenStyle)
func (*SemanticTheme) WithRules ¶ added in v1.0.0
func (s *SemanticTheme) WithRules(rules map[string]any) *SemanticTheme
WithRules makes the semantic theme with more rules, which win over the theme's: the rules of the user's editor.semanticTokenColorCustomizations. The selectors are the keys; a value is a color or an object with foreground and fontStyle (or bold, italic, underline, strikethrough). A selector or value that does not read is left out.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service holds the theme the UI uses (SPEC §5.1, §8.4): it picks the theme from the settings and the brightness of the system, loads it, and tells the listeners when it changes. It is safe for concurrent use; listeners are called on the goroutine that made the change.
func NewService ¶
func NewService(registry *ColorRegistry) *Service
NewService makes a service over a color registry, with Dark Modern as the theme until the settings are applied.
func (*Service) Apply ¶
Apply sets the settings that choose the theme. The theme in use is chosen again; when it changes, the listeners are told. When the theme the settings name does not exist or cannot be read, the default theme of the system's brightness is used and the error says why: it has the tag ThemeNotFound or the tags of Load.
Settings that differ from the ones applied before end a preview (EndPreview): the setting wins over a theme that is only being tried.
func (*Service) CurrentInfo ¶
CurrentInfo describes the theme in use.
func (*Service) EndPreview ¶
EndPreview goes back to the theme the settings choose. It does nothing when no preview is on. See Apply for the error.
func (*Service) OnChange ¶
func (s *Service) OnChange(fn func(*ColorTheme)) (unsubscribe func())
OnChange calls fn with the new theme whenever the theme in use changes. It gives a function that stops the calls.
func (*Service) PickerGroups ¶
func (s *Service) PickerGroups() ([]PickerGroup, error)
PickerGroups lists the themes that can be chosen in the groups of the picker, in its order: the light themes, the dark themes and the high contrast ones (both kinds), a group that has no theme left out. In each group the default theme comes first and the others by label. The error is that of Themes.
func (*Service) Preview ¶
Preview shows the theme with a label or id instead of the one the settings choose, until EndPreview, or until other settings are applied (SPEC §10.8). Nothing is written to the settings. The listeners are told when the theme in use changes. A theme that cannot be found or read leaves things as they were and fails with the tag ThemeNotFound or the tags of Load.
func (*Service) Previewing ¶
Previewing tells whether a theme is shown for a preview.
func (*Service) Registry ¶
func (s *Service) Registry() *ColorRegistry
Registry is the color registry the service resolves colors with.
func (*Service) SetPlatformBrightness ¶
SetPlatformBrightness tells the service whether the system is dark. It matters when window.autoDetectColorScheme is on.
func (*Service) SetUserThemes ¶
SetUserThemes sets the themes of the user's folder. The theme in use is chosen again, since the one the settings name may be among them now. See Apply for the error.
type Settings ¶
type Settings struct {
// ColorTheme is workbench.colorTheme: the label or id of the theme.
ColorTheme string
// AutoDetectColorScheme is window.autoDetectColorScheme: follow the light or dark scheme of
// the system with the two preferred themes.
AutoDetectColorScheme bool
// PreferredDarkColorTheme is workbench.preferredDarkColorTheme.
PreferredDarkColorTheme string
// PreferredLightColorTheme is workbench.preferredLightColorTheme.
PreferredLightColorTheme string
}
Settings are the settings that choose the theme (SPEC §8.4).
type Style ¶
type Style struct {
FontStyle FontStyle
Foreground int
Background int
FontFamily string
FontSize float64
LineHeight float64
}
Style is the style a theme gives to a token: the numbers of its colors in the color map of the theme (0 for none) and its font.
Ported from vscode-textmate: src/theme.ts (StyleAttributes)
type Theme ¶
type Theme struct {
// Name is the name in the theme file; empty when it has none.
Name string
// Type is the type in the theme file, or the one the caller said.
Type Type
// Colors are the workbench colors by id, as hex strings. A color the theme sets to "default"
// is not here.
Colors map[string]string
// TokenColors are the rules for the colors of tokens, those of the included themes first.
TokenColors []RawRule
// SemanticHighlighting tells whether the theme asks for semantic highlighting.
SemanticHighlighting bool
// SemanticTokenColors are the rules for semantic tokens as the file has them, kept for the
// language servers (area 3). The rules of an included theme come first.
SemanticTokenColors map[string]any
}
Theme is a color theme read from its files and the files it includes.
func Load ¶
Load reads the theme in the file name of fsys: JSON with comments, which may include another theme and may give its tokenColors in a file of their own (TextMate .tmTheme, or JSON), or a .tmTheme file itself. typ is the type of the theme when the file does not say; the error has one of the tags ThemeFileUnreadable, ThemeSyntaxError, ThemeNotObject, ThemeFieldInvalid, ThemeIncludeInvalid, ThemeIncludeCycle, TextMateThemeInvalid.
func LoadBundled ¶
LoadBundled loads a bundled theme by its label or its id.
func (*Theme) Color ¶
Color gives the workbench color with an id as the theme sets it, or "" when it does not.
func (*Theme) TokenRules ¶
TokenRules are the token color rules of the theme as the editor uses them: first the default rule, with the foreground and background of the editor; then the rules of the theme and the custom ones (which win), with their colors in upper case; and the rules for the info, warning, error and debug tokens unless the theme has its own.
Ported from VS Code: src/vs/workbench/services/themes/common/colorThemeData.ts (tokenColors)
func (*Theme) TokenTheme ¶
func (t *Theme) TokenTheme(custom []RawRule) *TokenTheme
TokenTheme resolves the token rules of the theme (see TokenRules) into the theme that gives a style to the scopes of a token.
type TokenTheme ¶
type TokenTheme struct {
// contains filtered or unexported fields
}
TokenTheme gives a style to the scopes of a token, resolving the token colors of a theme as vscode-textmate does.
Ported from vscode-textmate: src/theme.ts (Theme)
func NewTokenTheme ¶
func NewTokenTheme(rules []Rule) *TokenTheme
NewTokenTheme resolves rules: the rules with no scope make the defaults, the others a trie that gives each scope the rule that fits it best. The rules are sorted in place.
Ported from vscode-textmate: src/theme.ts (resolveParsedThemeRules)
func (*TokenTheme) Color ¶
func (t *TokenTheme) Color(id int) string
Color gives the color with a number.
func (*TokenTheme) Colors ¶
func (t *TokenTheme) Colors() []string
Colors are the colors of the theme by number; the one at 0 is empty.
func (*TokenTheme) Defaults ¶
func (t *TokenTheme) Defaults() Style
Defaults are the style of the text that no rule is for.
func (*TokenTheme) Match ¶
func (t *TokenTheme) Match(scopes []string) (style Style, ok bool)
Match gives the style of a token with the scopes, outermost first. With no scopes it is the defaults. ok is false when no rule fits the scopes, which is the case when the theme has a rule for the scope only below some parent that the token is not in.
Ported from vscode-textmate: src/theme.ts (Theme.match)
func (*TokenTheme) MatchStack ¶
func (t *TokenTheme) MatchStack(scopes *textmate.ScopeStack) (Style, bool)
MatchStack is Match for the scopes of a token as the tokenizer gives them.
func (*TokenTheme) Resolve ¶
func (t *TokenTheme) Resolve(scopes []string) Style
Resolve gives the style of a token with the scopes, outermost first: the defaults, changed by the rule that fits each scope with its ancestors, from the outermost scope in. A rule that sets only some of the style leaves the rest as the scopes before it made it, which is how the tokenizer of vscode-textmate gives a token its colors.
Ported from vscode-textmate: src/grammar/grammar.ts (AttributedScopeStack.mergeAttributes)
func (*TokenTheme) ResolveStack ¶
func (t *TokenTheme) ResolveStack(scopes *textmate.ScopeStack) Style
ResolveStack is Resolve for the scopes of a token as the tokenizer gives them.
func (*TokenTheme) Semantic ¶ added in v1.0.0
func (t *TokenTheme) Semantic() *SemanticTheme
Semantic is the semantic token styling of the theme the token theme was made from; nil for a token theme that was made from rules alone.
type Type ¶
type Type string
Type is the kind of a theme: it decides the defaults of the colors that the theme does not set.
type UserTheme ¶
UserTheme is a theme from the folder of the user's themes.
func LoadUserThemes ¶
LoadUserThemes reads the themes in a folder: the JSON and .tmTheme files in the root of fsys ($XDG_CONFIG_HOME/emetos/themes/), ordered by file name. A file that cannot be read as a theme is left out and its error is among the problems; a theme without a type is dark. The error has the tag UserThemesUnreadable when the folder cannot be listed.