themes

package
v0.74.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: AGPL-3.0 Imports: 20 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 themes stores user-imported color themes and exposes them to the UI.

Index

Constants

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

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

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

func Schema() ([]byte, error)

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

type BrokenTheme struct {
	ID     string `json:"id"`
	Reason string `json:"reason"`
}

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

type ImportResult struct {
	Theme          Theme `json:"theme"`
	NeedsOverwrite bool  `json:"needsOverwrite"`
}

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

type Selection struct {
	Theme        string `json:"theme"`
	FollowSystem bool   `json:"followSystem"`
}

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

func New(lichVersion string, settings Settings, emit func(name string, data any)) *Service

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 NewInDir

func NewInDir(dir string) *Service

NewInDir returns a theme service rooted at dir. It is used by tests.

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

func (s *Service) List() ([]Theme, error)

List returns bundled themes followed by custom themes sorted by name.

func (*Service) ListBroken

func (s *Service) ListBroken() ([]BrokenTheme, error)

ListBroken returns the stored custom themes List leaves out, sorted by id.

func (*Service) Remove

func (s *Service) Remove(id string) error

Remove deletes a custom theme. Bundled and reserved ids cannot be removed.

func (*Service) SaveTemplate

func (s *Service) SaveTemplate(path string) error

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

func (s *Service) Selection() (Selection, error)

Selection reads the stored selection.

func (*Service) SetFollowSystem

func (s *Service) SetFollowSystem(on bool) error

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

type Source struct {
	URL     string `json:"url"`
	Version string `json:"version"`
}

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

func (s *Syntax) UnmarshalJSON(data []byte) error

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.

Jump to

Keyboard shortcuts

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