theme

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package theme holds color themes, token colors and the workbench color registry (SPEC §8.4).

Index

Constants

View Source
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.

View Source
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.

View Source
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

View Source
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

func PickDescription(info Info) string

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

func NewColor(r, g, b, a float64) Color

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

func ParseColor(s string) (c Color, ok bool)

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) ARGB

func (c Color) ARGB() uint32

ARGB is the color as 0xAARRGGBB, which is how Glutter writes a color.

func (Color) Blend

func (c Color) Blend(background Color) Color

Blend gives the color that this one makes when it is laid over a background.

func (Color) Darken

func (c Color) Darken(factor float64) Color

Darken lowers the lightness by the factor of itself.

func (Color) Equal

func (c Color) Equal(o Color) bool

Equal tells whether two colors are the same in red, green, blue and alpha.

func (Color) Hex

func (c Color) Hex() string

Hex writes the color as #rrggbb, or #rrggbbaa when it is not opaque.

func (Color) IsDarkerThan

func (c Color) IsDarkerThan(o Color) bool

IsDarkerThan tells whether the color has a lower relative luminance than another.

func (Color) IsLighterThan

func (c Color) IsLighterThan(o Color) bool

IsLighterThan tells whether the color has a higher relative luminance than another.

func (Color) IsOpaque

func (c Color) IsOpaque() bool

IsOpaque tells whether the alpha is 1.

func (Color) Lighten

func (c Color) Lighten(factor float64) Color

Lighten raises the lightness by the factor of itself (0.1 is a tenth more).

func (Color) MakeOpaque

func (c Color) MakeOpaque(background Color) Color

MakeOpaque gives the opaque color that looks like this one over an opaque background.

func (Color) Mix

func (c Color) Mix(other Color, factor float64) Color

Mix mixes the color with another: a factor of 0 is this color, 1 the other, 0.5 half of each.

func (Color) RGBA

func (c Color) RGBA() (r, g, b int, a float64)

RGBA gives the red, green and blue (0 to 255) and the alpha (0 to 1).

func (Color) RelativeLuminance

func (c Color) RelativeLuminance() float64

RelativeLuminance is the WCAG relative luminance, from 0 (black) to 1 (white).

func (Color) String

func (c Color) String() string

String writes the color as VS Code does: #rrggbb when it is opaque, else rgba(r, g, b, a).

func (Color) WithAlphaFactor

func (c Color) WithAlphaFactor(factor float64) Color

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 NewColorMap

func NewColorMap() *ColorMap

NewColorMap makes an empty color map.

func (*ColorMap) Color

func (m *ColorMap) Color(id int) string

Color gives the color with a number, or "" for 0 or a number that is not used.

func (*ColorMap) Colors

func (m *ColorMap) Colors() []string

Colors are the colors by number; the one at 0 is empty.

func (*ColorMap) ID

func (m *ColorMap) ID(color string) int

ID gives the number of a color, adding the color when it is new. The empty color is 0.

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.

func (*ColorTheme) Type

func (ct *ColorTheme) Type() Type

Type is the type of the theme.

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 Lit

func Lit(c Color) ColorValue

Lit is a color value that is the color c.

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) ID

func (t *FileIconTheme) ID() string

ID is the id of the theme.

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.

func (FontStyle) String

func (f FontStyle) String() string

String writes the style as vscode-textmate's fontStyleToString does: "not set", "none" or the names of the flags in the order italic, bold, underline, strikethrough.

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.

func Bundled

func Bundled() ([]Info, error)

Bundled lists the themes that come with Emetos: Dark Modern, Light Modern, Dark+, Light+, Dark High Contrast and Light High Contrast, in the order of the manifest of VS Code's default themes. The error has the tag BundledThemesInvalid when the manifest cannot be read.

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

func ParseRules(raw []RawRule) []Rule

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).

func ScopeList

func ScopeList(selectors ...string) Scope

ScopeList is a scope that is a list of selectors.

func ScopeText

func ScopeText(s string) Scope

ScopeText is a scope that is a string, such as "comment, string".

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

func (s *Service) Apply(settings Settings) error

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) Current

func (s *Service) Current() *ColorTheme

Current is the theme in use.

func (*Service) CurrentInfo

func (s *Service) CurrentInfo() Info

CurrentInfo describes the theme in use.

func (*Service) EndPreview

func (s *Service) EndPreview() error

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

func (s *Service) Preview(name string) error

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

func (s *Service) Previewing() bool

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

func (s *Service) SetPlatformBrightness(dark bool) error

SetPlatformBrightness tells the service whether the system is dark. It matters when window.autoDetectColorScheme is on.

func (*Service) SetUserThemes

func (s *Service) SetUserThemes(themes []UserTheme) error

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.

func (*Service) Themes

func (s *Service) Themes() ([]Info, error)

Themes lists the themes that can be chosen: the bundled ones, then the user's.

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

func Load(fsys fs.FS, name string, typ Type) (*Theme, error)

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

func LoadBundled(name string) (*Theme, error)

LoadBundled loads a bundled theme by its label or its id.

func (*Theme) Color

func (t *Theme) Color(id string) string

Color gives the workbench color with an id as the theme sets it, or "" when it does not.

func (*Theme) TokenRules

func (t *Theme) TokenRules(custom []RawRule) []RawRule

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.

const (
	// TypeDark is a dark theme.
	TypeDark Type = "dark"
	// TypeLight is a light theme.
	TypeLight Type = "light"
	// TypeHCDark is a dark high contrast theme.
	TypeHCDark Type = "hc-dark"
	// TypeHCLight is a light high contrast theme.
	TypeHCLight Type = "hc-light"
)

The theme types.

func ParseType

func ParseType(s string) (Type, bool)

ParseType reads the type of a theme as a theme file or an extension's uiTheme writes it.

type UserTheme

type UserTheme struct {
	Info
	// Theme is the theme read from the file.
	Theme *Theme
}

UserTheme is a theme from the folder of the user's themes.

func LoadUserThemes

func LoadUserThemes(fsys fs.FS) ([]UserTheme, []error, error)

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.

Jump to

Keyboard shortcuts

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