Documentation
¶
Overview ¶
Package themes stores user-imported color themes and exposes them to the UI.
Index ¶
- Constants
- func Schema() ([]byte, error)
- type BrokenTheme
- type GitInstallResult
- type ImportResult
- type Manifest
- type SelectOptions
- type Selection
- type Service
- func (s *Service) Import(path string, overwrite bool) (ImportResult, error)
- func (s *Service) InstallFromGit(url string, overwrite bool) (GitInstallResult, error)
- func (s *Service) List() ([]Theme, error)
- func (s *Service) ListBroken() ([]BrokenTheme, error)
- func (s *Service) Remove(id string) error
- func (s *Service) SaveTemplate(path string) error
- func (s *Service) Select(opts SelectOptions) error
- func (s *Service) Selection() (Selection, error)
- func (s *Service) SetFollowSystem(on bool) error
- func (s *Service) UpdateFromGit(id string) (GitInstallResult, error)
- type Settings
- type Source
- type Syntax
- type SyntaxStyle
- type Theme
Constants ¶
const ( ThemeSettingKey = "appearance.theme" FollowSystemSettingKey = "appearance.followSystem" // SystemID selects the bundled theme of the scheme the OS asks for. SystemID = "system" )
The settings the windows read the selection from, global ones. A theme key never written reads "", which is System.
const ( OriginBundled = "bundled" OriginCustom = "custom" SchemeLight = "light" SchemeDark = "dark" // FormatVersion is the newest theme file format this lich reads. A file // that omits it is format 1; bump it only for a change an older lich would // misread, so that lich refuses the file by name instead of by a token. FormatVersion = 1 )
const SchemaPath = "themes/lich-theme.schema.json"
SchemaPath is where the generated schema lives in this repository, and the tail of the raw URL a theme author points "$schema" at.
const SelectionEventName = "theme-selection"
SelectionEventName is pushed on /events with a Selection once a change to it is stored.
Variables ¶
This section is empty.
Functions ¶
func Schema ¶
Schema renders the JSON Schema a theme file is checked against in an editor. It is generated from the same token sets and patterns validateTheme reads, so a token added to the bundled theme cannot leave the schema behind; the test beside this file fails when the checked-in copy has drifted.
Types ¶
type BrokenTheme ¶
BrokenTheme is a stored custom theme this lich cannot load. It is listed rather than dropped, so the user sees why and can remove it by id.
type GitInstallResult ¶
type GitInstallResult struct {
Pack string `json:"pack"`
Version string `json:"version"`
Themes []Theme `json:"themes"`
Conflicts []string `json:"conflicts"`
UpToDate bool `json:"upToDate"`
}
GitInstallResult reports what installing a repository produced. Conflicts names the theme ids that already exist locally: found by the scan that runs before any write, nothing was installed at all; found by the write itself — a theme that appeared in between — that one id was left alone and Themes says what did go in.
type ImportResult ¶
ImportResult either reports the installed theme or asks the UI to confirm replacing the existing custom theme with the same id.
type Manifest ¶
type Manifest struct {
FormatVersion int `json:"formatVersion,omitempty"`
Name string `json:"name"`
Version string `json:"version"`
// MinLichVersion is the oldest lich release the pack's themes are written
// for, so an older lich refuses the pack by name before it trips on a token.
MinLichVersion string `json:"minLichVersion,omitempty"`
}
Manifest is the versioning stamp of a theme repository. It deliberately does not list the themes: id and name already live inside each theme file, and a second copy here would be a list to keep in sync for no gain.
type SelectOptions ¶
type SelectOptions struct {
ID string `json:"id"`
}
SelectOptions names the theme Select stores.
type Selection ¶
Selection is the theme the user chose and whether the window draws that theme's pair while the OS asks for the pair's scheme.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service reads bundled themes plus user-imported themes.
func New ¶
New returns a theme service rooted under lich's config directory, checking theme packs against lichVersion, the running build's version. It stores the selection in settings and reports a change to it through emit.
func (*Service) Import ¶
func (s *Service) Import(path string, overwrite bool) (ImportResult, error)
Import reads a picked JSON file and installs it as a custom theme. An existing id is reported without changing it unless overwrite is true.
func (*Service) InstallFromGit ¶
func (s *Service) InstallFromGit(url string, overwrite bool) (GitInstallResult, error)
InstallFromGit clones a theme repository and installs every theme in it. The pack is validated as a whole before anything is written, so one unreadable or invalid theme fails the whole repository. The writing is per file, though: a disk error partway through leaves the themes already written in place.
func (*Service) ListBroken ¶
func (s *Service) ListBroken() ([]BrokenTheme, error)
ListBroken returns the stored custom themes List leaves out, sorted by id.
func (*Service) SaveTemplate ¶
SaveTemplate writes the bundled starter theme to a destination the user picked. The save dialog already confirmed replacing an existing file.
func (*Service) Select ¶
func (s *Service) Select(opts SelectOptions) error
Select stores opts.ID, System or a theme List returns, as the selection.
func (*Service) SetFollowSystem ¶
SetFollowSystem stores whether the window follows the OS to the selected theme's pair.
func (*Service) UpdateFromGit ¶
func (s *Service) UpdateFromGit(id string) (GitInstallResult, error)
UpdateFromGit re-clones the repository a theme came from and installs it again when the manifest carries a newer version. The whole pack moves together — the repository, not the single theme, is what is versioned.
type Settings ¶
type Settings interface {
GetSetting(key, projectID string) (string, error)
SetSetting(key, projectID, value string) error
}
Settings is where the selection is stored: the store's global settings.
type Source ¶
Source records the repository a theme was installed from and the manifest version it came in at, so lich can clone it again to look for a newer one. It is written by lich, never by a picked file: a standalone import has no source and stays unversioned.
type Syntax ¶
type Syntax map[string]SyntaxStyle
Syntax is a theme's syntax highlighting, keyed by the tag each style is for, as @lezer/highlight prints it: "keyword", "function(variableName)".
func (*Syntax) UnmarshalJSON ¶
UnmarshalJSON reads each entry as a bare color or a style object, naming the entry that is neither.
type SyntaxStyle ¶
type SyntaxStyle struct {
Color string `json:"color,omitempty"`
Bold bool `json:"bold,omitempty"`
Italic bool `json:"italic,omitempty"`
Underline bool `json:"underline,omitempty"`
Strikethrough bool `json:"strikethrough,omitempty"`
}
SyntaxStyle is how the code under one highlighting tag is drawn: a CodeMirror HighlightStyle spec. A theme file writes it as a bare color or as an object; Color empty leaves the code its foreground color.
type Theme ¶
type Theme struct {
FormatVersion int `json:"formatVersion,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Scheme string `json:"scheme"`
Origin string `json:"origin"`
Source *Source `json:"source,omitempty"`
App map[string]string `json:"app"`
Terminal map[string]string `json:"terminal"`
// Syntax is optional: a theme without it is highlighted in the window's
// default palette for its scheme.
Syntax Syntax `json:"syntax,omitempty"`
// Pair is optional: the id of this theme's variant for the other scheme,
// which the window draws while the OS asks for that scheme and the user
// turned on following it.
Pair string `json:"pair,omitempty"`
}
Theme describes every color value the window needs to paint the app and the terminal.