2023-02-26 12:51:49 +03:00
|
|
|
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
|
|
|
|
|
|
|
package themes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"archive/zip"
|
2023-03-14 17:54:21 +03:00
|
|
|
"bytes"
|
2023-02-26 12:51:49 +03:00
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/fs"
|
2024-05-04 12:04:40 +03:00
|
|
|
"maps"
|
2023-02-26 12:51:49 +03:00
|
|
|
"net/http"
|
|
|
|
"os"
|
2023-02-26 18:10:59 +03:00
|
|
|
"path"
|
2023-02-26 12:51:49 +03:00
|
|
|
"path/filepath"
|
2023-02-26 18:10:59 +03:00
|
|
|
"regexp"
|
2024-05-04 12:04:40 +03:00
|
|
|
"slices"
|
2023-02-27 05:30:13 +03:00
|
|
|
"strconv"
|
2023-02-26 18:10:59 +03:00
|
|
|
"strings"
|
2023-08-09 09:38:42 +03:00
|
|
|
"sync"
|
2023-02-26 12:51:49 +03:00
|
|
|
"time"
|
2023-02-26 18:10:59 +03:00
|
|
|
|
2023-03-11 07:44:03 +03:00
|
|
|
"kitty/tools/cli"
|
|
|
|
"kitty/tools/config"
|
2023-03-18 12:44:31 +03:00
|
|
|
"kitty/tools/tui/loop"
|
2023-03-12 19:04:54 +03:00
|
|
|
"kitty/tools/tui/subseq"
|
2023-03-11 07:44:03 +03:00
|
|
|
"kitty/tools/utils"
|
|
|
|
"kitty/tools/utils/style"
|
2023-02-26 12:51:49 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = fmt.Print
|
|
|
|
|
2023-03-11 07:44:03 +03:00
|
|
|
var AllColorSettingNames = map[string]bool{ // {{{
|
|
|
|
// generated by gen-config.py do not edit
|
|
|
|
// ALL_COLORS_START
|
|
|
|
"active_border_color": true,
|
|
|
|
"active_tab_background": true,
|
|
|
|
"active_tab_foreground": true,
|
|
|
|
"background": true,
|
|
|
|
"bell_border_color": true,
|
|
|
|
"color0": true,
|
|
|
|
"color1": true,
|
|
|
|
"color10": true,
|
|
|
|
"color100": true,
|
|
|
|
"color101": true,
|
|
|
|
"color102": true,
|
|
|
|
"color103": true,
|
|
|
|
"color104": true,
|
|
|
|
"color105": true,
|
|
|
|
"color106": true,
|
|
|
|
"color107": true,
|
|
|
|
"color108": true,
|
|
|
|
"color109": true,
|
|
|
|
"color11": true,
|
|
|
|
"color110": true,
|
|
|
|
"color111": true,
|
|
|
|
"color112": true,
|
|
|
|
"color113": true,
|
|
|
|
"color114": true,
|
|
|
|
"color115": true,
|
|
|
|
"color116": true,
|
|
|
|
"color117": true,
|
|
|
|
"color118": true,
|
|
|
|
"color119": true,
|
|
|
|
"color12": true,
|
|
|
|
"color120": true,
|
|
|
|
"color121": true,
|
|
|
|
"color122": true,
|
|
|
|
"color123": true,
|
|
|
|
"color124": true,
|
|
|
|
"color125": true,
|
|
|
|
"color126": true,
|
|
|
|
"color127": true,
|
|
|
|
"color128": true,
|
|
|
|
"color129": true,
|
|
|
|
"color13": true,
|
|
|
|
"color130": true,
|
|
|
|
"color131": true,
|
|
|
|
"color132": true,
|
|
|
|
"color133": true,
|
|
|
|
"color134": true,
|
|
|
|
"color135": true,
|
|
|
|
"color136": true,
|
|
|
|
"color137": true,
|
|
|
|
"color138": true,
|
|
|
|
"color139": true,
|
|
|
|
"color14": true,
|
|
|
|
"color140": true,
|
|
|
|
"color141": true,
|
|
|
|
"color142": true,
|
|
|
|
"color143": true,
|
|
|
|
"color144": true,
|
|
|
|
"color145": true,
|
|
|
|
"color146": true,
|
|
|
|
"color147": true,
|
|
|
|
"color148": true,
|
|
|
|
"color149": true,
|
|
|
|
"color15": true,
|
|
|
|
"color150": true,
|
|
|
|
"color151": true,
|
|
|
|
"color152": true,
|
|
|
|
"color153": true,
|
|
|
|
"color154": true,
|
|
|
|
"color155": true,
|
|
|
|
"color156": true,
|
|
|
|
"color157": true,
|
|
|
|
"color158": true,
|
|
|
|
"color159": true,
|
|
|
|
"color16": true,
|
|
|
|
"color160": true,
|
|
|
|
"color161": true,
|
|
|
|
"color162": true,
|
|
|
|
"color163": true,
|
|
|
|
"color164": true,
|
|
|
|
"color165": true,
|
|
|
|
"color166": true,
|
|
|
|
"color167": true,
|
|
|
|
"color168": true,
|
|
|
|
"color169": true,
|
|
|
|
"color17": true,
|
|
|
|
"color170": true,
|
|
|
|
"color171": true,
|
|
|
|
"color172": true,
|
|
|
|
"color173": true,
|
|
|
|
"color174": true,
|
|
|
|
"color175": true,
|
|
|
|
"color176": true,
|
|
|
|
"color177": true,
|
|
|
|
"color178": true,
|
|
|
|
"color179": true,
|
|
|
|
"color18": true,
|
|
|
|
"color180": true,
|
|
|
|
"color181": true,
|
|
|
|
"color182": true,
|
|
|
|
"color183": true,
|
|
|
|
"color184": true,
|
|
|
|
"color185": true,
|
|
|
|
"color186": true,
|
|
|
|
"color187": true,
|
|
|
|
"color188": true,
|
|
|
|
"color189": true,
|
|
|
|
"color19": true,
|
|
|
|
"color190": true,
|
|
|
|
"color191": true,
|
|
|
|
"color192": true,
|
|
|
|
"color193": true,
|
|
|
|
"color194": true,
|
|
|
|
"color195": true,
|
|
|
|
"color196": true,
|
|
|
|
"color197": true,
|
|
|
|
"color198": true,
|
|
|
|
"color199": true,
|
|
|
|
"color2": true,
|
|
|
|
"color20": true,
|
|
|
|
"color200": true,
|
|
|
|
"color201": true,
|
|
|
|
"color202": true,
|
|
|
|
"color203": true,
|
|
|
|
"color204": true,
|
|
|
|
"color205": true,
|
|
|
|
"color206": true,
|
|
|
|
"color207": true,
|
|
|
|
"color208": true,
|
|
|
|
"color209": true,
|
|
|
|
"color21": true,
|
|
|
|
"color210": true,
|
|
|
|
"color211": true,
|
|
|
|
"color212": true,
|
|
|
|
"color213": true,
|
|
|
|
"color214": true,
|
|
|
|
"color215": true,
|
|
|
|
"color216": true,
|
|
|
|
"color217": true,
|
|
|
|
"color218": true,
|
|
|
|
"color219": true,
|
|
|
|
"color22": true,
|
|
|
|
"color220": true,
|
|
|
|
"color221": true,
|
|
|
|
"color222": true,
|
|
|
|
"color223": true,
|
|
|
|
"color224": true,
|
|
|
|
"color225": true,
|
|
|
|
"color226": true,
|
|
|
|
"color227": true,
|
|
|
|
"color228": true,
|
|
|
|
"color229": true,
|
|
|
|
"color23": true,
|
|
|
|
"color230": true,
|
|
|
|
"color231": true,
|
|
|
|
"color232": true,
|
|
|
|
"color233": true,
|
|
|
|
"color234": true,
|
|
|
|
"color235": true,
|
|
|
|
"color236": true,
|
|
|
|
"color237": true,
|
|
|
|
"color238": true,
|
|
|
|
"color239": true,
|
|
|
|
"color24": true,
|
|
|
|
"color240": true,
|
|
|
|
"color241": true,
|
|
|
|
"color242": true,
|
|
|
|
"color243": true,
|
|
|
|
"color244": true,
|
|
|
|
"color245": true,
|
|
|
|
"color246": true,
|
|
|
|
"color247": true,
|
|
|
|
"color248": true,
|
|
|
|
"color249": true,
|
|
|
|
"color25": true,
|
|
|
|
"color250": true,
|
|
|
|
"color251": true,
|
|
|
|
"color252": true,
|
|
|
|
"color253": true,
|
|
|
|
"color254": true,
|
|
|
|
"color255": true,
|
|
|
|
"color26": true,
|
|
|
|
"color27": true,
|
|
|
|
"color28": true,
|
|
|
|
"color29": true,
|
|
|
|
"color3": true,
|
|
|
|
"color30": true,
|
|
|
|
"color31": true,
|
|
|
|
"color32": true,
|
|
|
|
"color33": true,
|
|
|
|
"color34": true,
|
|
|
|
"color35": true,
|
|
|
|
"color36": true,
|
|
|
|
"color37": true,
|
|
|
|
"color38": true,
|
|
|
|
"color39": true,
|
|
|
|
"color4": true,
|
|
|
|
"color40": true,
|
|
|
|
"color41": true,
|
|
|
|
"color42": true,
|
|
|
|
"color43": true,
|
|
|
|
"color44": true,
|
|
|
|
"color45": true,
|
|
|
|
"color46": true,
|
|
|
|
"color47": true,
|
|
|
|
"color48": true,
|
|
|
|
"color49": true,
|
|
|
|
"color5": true,
|
|
|
|
"color50": true,
|
|
|
|
"color51": true,
|
|
|
|
"color52": true,
|
|
|
|
"color53": true,
|
|
|
|
"color54": true,
|
|
|
|
"color55": true,
|
|
|
|
"color56": true,
|
|
|
|
"color57": true,
|
|
|
|
"color58": true,
|
|
|
|
"color59": true,
|
|
|
|
"color6": true,
|
|
|
|
"color60": true,
|
|
|
|
"color61": true,
|
|
|
|
"color62": true,
|
|
|
|
"color63": true,
|
|
|
|
"color64": true,
|
|
|
|
"color65": true,
|
|
|
|
"color66": true,
|
|
|
|
"color67": true,
|
|
|
|
"color68": true,
|
|
|
|
"color69": true,
|
|
|
|
"color7": true,
|
|
|
|
"color70": true,
|
|
|
|
"color71": true,
|
|
|
|
"color72": true,
|
|
|
|
"color73": true,
|
|
|
|
"color74": true,
|
|
|
|
"color75": true,
|
|
|
|
"color76": true,
|
|
|
|
"color77": true,
|
|
|
|
"color78": true,
|
|
|
|
"color79": true,
|
|
|
|
"color8": true,
|
|
|
|
"color80": true,
|
|
|
|
"color81": true,
|
|
|
|
"color82": true,
|
|
|
|
"color83": true,
|
|
|
|
"color84": true,
|
|
|
|
"color85": true,
|
|
|
|
"color86": true,
|
|
|
|
"color87": true,
|
|
|
|
"color88": true,
|
|
|
|
"color89": true,
|
|
|
|
"color9": true,
|
|
|
|
"color90": true,
|
|
|
|
"color91": true,
|
|
|
|
"color92": true,
|
|
|
|
"color93": true,
|
|
|
|
"color94": true,
|
|
|
|
"color95": true,
|
|
|
|
"color96": true,
|
|
|
|
"color97": true,
|
|
|
|
"color98": true,
|
|
|
|
"color99": true,
|
|
|
|
"cursor": true,
|
|
|
|
"cursor_text_color": true,
|
|
|
|
"foreground": true,
|
|
|
|
"inactive_border_color": true,
|
|
|
|
"inactive_tab_background": true,
|
|
|
|
"inactive_tab_foreground": true,
|
|
|
|
"macos_titlebar_color": true,
|
|
|
|
"mark1_background": true,
|
|
|
|
"mark1_foreground": true,
|
|
|
|
"mark2_background": true,
|
|
|
|
"mark2_foreground": true,
|
|
|
|
"mark3_background": true,
|
|
|
|
"mark3_foreground": true,
|
|
|
|
"selection_background": true,
|
|
|
|
"selection_foreground": true,
|
|
|
|
"tab_bar_background": true,
|
|
|
|
"tab_bar_margin_color": true,
|
|
|
|
"url_color": true,
|
|
|
|
"visual_bell_color": true,
|
|
|
|
"wayland_titlebar_color": true, // ALL_COLORS_END
|
|
|
|
} // }}}
|
|
|
|
|
2023-02-26 12:51:49 +03:00
|
|
|
type JSONMetadata struct {
|
|
|
|
Etag string `json:"etag"`
|
|
|
|
Timestamp string `json:"timestamp"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var ErrNoCacheFound = errors.New("No cache found and max cache age is negative")
|
|
|
|
|
2023-03-14 17:54:21 +03:00
|
|
|
func set_comment_in_zip_file(path string, comment string) error {
|
|
|
|
src, err := zip.OpenReader(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer src.Close()
|
|
|
|
buf := bytes.Buffer{}
|
|
|
|
dest := zip.NewWriter(&buf)
|
2023-09-18 18:08:08 +03:00
|
|
|
if err = dest.SetComment(comment); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-14 17:54:21 +03:00
|
|
|
for _, sf := range src.File {
|
|
|
|
err = dest.Copy(sf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dest.Close()
|
2024-07-22 12:31:19 +03:00
|
|
|
return utils.AtomicUpdateFile(path, bytes.NewReader(buf.Bytes()), 0o644)
|
2023-03-14 17:54:21 +03:00
|
|
|
}
|
|
|
|
|
2023-02-26 19:26:03 +03:00
|
|
|
func fetch_cached(name, url, cache_path string, max_cache_age time.Duration) (string, error) {
|
|
|
|
cache_path = filepath.Join(cache_path, name+".zip")
|
2023-02-26 12:51:49 +03:00
|
|
|
zf, err := zip.OpenReader(cache_path)
|
|
|
|
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
|
|
|
return "", err
|
|
|
|
}
|
2023-02-26 19:26:03 +03:00
|
|
|
|
2023-02-26 12:51:49 +03:00
|
|
|
var jm JSONMetadata
|
|
|
|
if err == nil {
|
2023-03-14 18:02:38 +03:00
|
|
|
defer zf.Close()
|
2023-09-18 18:08:08 +03:00
|
|
|
if err = json.Unmarshal(utils.UnsafeStringToBytes(zf.Comment), &jm); err == nil {
|
|
|
|
if max_cache_age < 0 {
|
2023-02-26 12:51:49 +03:00
|
|
|
return cache_path, nil
|
|
|
|
}
|
2023-09-18 18:08:08 +03:00
|
|
|
cache_age, err := utils.ISO8601Parse(jm.Timestamp)
|
|
|
|
if err == nil {
|
|
|
|
if time.Now().Before(cache_age.Add(max_cache_age)) {
|
|
|
|
return cache_path, nil
|
|
|
|
}
|
|
|
|
}
|
2023-02-26 12:51:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if max_cache_age < 0 {
|
|
|
|
return "", ErrNoCacheFound
|
|
|
|
}
|
|
|
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if jm.Etag != "" {
|
|
|
|
req.Header.Add("If-None-Match", jm.Etag)
|
|
|
|
}
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Failed to download %s with error: %w", url, err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
2023-02-26 19:26:03 +03:00
|
|
|
if resp.StatusCode == http.StatusNotModified {
|
2023-03-14 17:54:21 +03:00
|
|
|
jm.Timestamp = utils.ISO8601Format(time.Now())
|
|
|
|
comment, _ := json.Marshal(jm)
|
|
|
|
err = set_comment_in_zip_file(cache_path, utils.UnsafeBytesToString(comment))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2023-02-26 19:26:03 +03:00
|
|
|
return cache_path, nil
|
|
|
|
}
|
2023-02-26 12:51:49 +03:00
|
|
|
return "", fmt.Errorf("Failed to download %s with HTTP error: %s", url, resp.Status)
|
|
|
|
}
|
|
|
|
var tf, tf2 *os.File
|
|
|
|
tf, err = os.CreateTemp(filepath.Dir(cache_path), name+".temp-*")
|
|
|
|
if err == nil {
|
|
|
|
tf2, err = os.CreateTemp(filepath.Dir(cache_path), name+".temp-*")
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if tf != nil {
|
|
|
|
tf.Close()
|
|
|
|
os.Remove(tf.Name())
|
|
|
|
tf = nil
|
|
|
|
}
|
|
|
|
if tf2 != nil {
|
|
|
|
tf2.Close()
|
|
|
|
os.Remove(tf2.Name())
|
|
|
|
tf2 = nil
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Failed to create temp file in %s with error: %w", filepath.Dir(cache_path), err)
|
|
|
|
}
|
|
|
|
_, err = io.Copy(tf, resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Failed to download %s with error: %w", url, err)
|
|
|
|
}
|
|
|
|
r, err := zip.OpenReader(tf.Name())
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Failed to open downloaded zip file with error: %w", err)
|
|
|
|
}
|
2023-03-14 18:12:36 +03:00
|
|
|
defer r.Close()
|
2023-02-26 12:51:49 +03:00
|
|
|
w := zip.NewWriter(tf2)
|
|
|
|
jm.Etag = resp.Header.Get("ETag")
|
|
|
|
jm.Timestamp = utils.ISO8601Format(time.Now())
|
|
|
|
comment, _ := json.Marshal(jm)
|
2023-09-18 18:08:08 +03:00
|
|
|
if err = w.SetComment(utils.UnsafeBytesToString(comment)); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2023-02-26 12:51:49 +03:00
|
|
|
for _, file := range r.File {
|
|
|
|
err = w.Copy(file)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Failed to copy zip file from source to destination archive")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = w.Close()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
tf2.Close()
|
|
|
|
err = os.Rename(tf2.Name(), cache_path)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("Failed to atomic rename temp file to %s with error: %w", cache_path, err)
|
|
|
|
}
|
|
|
|
tf2 = nil
|
|
|
|
return cache_path, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func FetchCached(max_cache_age time.Duration) (string, error) {
|
2023-02-26 19:26:03 +03:00
|
|
|
return fetch_cached("kitty-themes", "https://codeload.github.com/kovidgoyal/kitty-themes/zip/master", utils.CacheDir(), max_cache_age)
|
2023-02-26 12:51:49 +03:00
|
|
|
}
|
2023-02-26 18:10:59 +03:00
|
|
|
|
|
|
|
type ThemeMetadata struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Filepath string `json:"file"`
|
|
|
|
Is_dark bool `json:"is_dark"`
|
|
|
|
Num_settings int `json:"num_settings"`
|
|
|
|
Blurb string `json:"blurb"`
|
|
|
|
License string `json:"license"`
|
|
|
|
Upstream string `json:"upstream"`
|
|
|
|
Author string `json:"author"`
|
|
|
|
}
|
|
|
|
|
2023-05-04 07:44:58 +03:00
|
|
|
func ParseThemeMetadata(path string) (*ThemeMetadata, map[string]string, error) {
|
2023-02-26 18:10:59 +03:00
|
|
|
var in_metadata, in_blurb, finished_metadata bool
|
2023-10-05 07:06:59 +03:00
|
|
|
ans := ThemeMetadata{Is_dark: true} // the default background in kitty is dark
|
2023-02-27 05:30:13 +03:00
|
|
|
settings := map[string]string{}
|
2023-10-05 07:06:59 +03:00
|
|
|
|
2023-02-26 18:46:29 +03:00
|
|
|
read_is_dark := func(key, val string) (err error) {
|
2023-02-27 05:30:13 +03:00
|
|
|
settings[key] = val
|
2023-02-26 18:46:29 +03:00
|
|
|
if key == "background" {
|
|
|
|
if val != "" {
|
|
|
|
bg, err := style.ParseColor(val)
|
|
|
|
if err == nil {
|
2023-10-05 07:06:59 +03:00
|
|
|
ans.Is_dark = utils.Max(bg.Red, bg.Green, bg.Blue) < 115
|
2023-02-26 18:46:29 +03:00
|
|
|
}
|
|
|
|
}
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
2023-02-26 18:46:29 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
read_metadata := func(line string) (err error) {
|
2023-02-26 18:10:59 +03:00
|
|
|
is_block := strings.HasPrefix(line, "## ")
|
|
|
|
if in_metadata && !is_block {
|
|
|
|
finished_metadata = true
|
|
|
|
}
|
|
|
|
if finished_metadata {
|
2023-02-26 18:46:29 +03:00
|
|
|
return
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
if !in_metadata && is_block {
|
|
|
|
in_metadata = true
|
|
|
|
}
|
|
|
|
if !in_metadata {
|
2023-02-26 18:46:29 +03:00
|
|
|
return
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
line = line[3:]
|
|
|
|
if in_blurb {
|
|
|
|
ans.Blurb += " " + line
|
2023-02-26 18:46:29 +03:00
|
|
|
return
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
key, val, found := strings.Cut(line, ":")
|
|
|
|
if !found {
|
2023-02-26 18:46:29 +03:00
|
|
|
return
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
key = strings.TrimSpace(strings.ToLower(key))
|
|
|
|
val = strings.TrimSpace(val)
|
|
|
|
switch key {
|
|
|
|
case "name":
|
2023-05-03 19:25:33 +03:00
|
|
|
if val != "The name of the theme (if not present, derived from filename)" {
|
|
|
|
ans.Name = val
|
|
|
|
}
|
2023-02-26 18:10:59 +03:00
|
|
|
case "author":
|
|
|
|
ans.Author = val
|
|
|
|
case "upstream":
|
|
|
|
ans.Upstream = val
|
|
|
|
case "blurb":
|
|
|
|
ans.Blurb = val
|
|
|
|
in_blurb = true
|
|
|
|
case "license":
|
|
|
|
ans.License = val
|
|
|
|
}
|
2023-02-26 18:46:29 +03:00
|
|
|
return
|
|
|
|
}
|
2023-02-27 05:30:13 +03:00
|
|
|
cp := config.ConfigParser{LineHandler: read_is_dark, CommentsHandler: read_metadata}
|
2023-02-26 18:46:29 +03:00
|
|
|
err := cp.ParseFiles(path)
|
|
|
|
if err != nil {
|
2023-02-27 05:30:13 +03:00
|
|
|
return nil, nil, err
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
2023-02-27 05:30:13 +03:00
|
|
|
ans.Num_settings = len(settings)
|
|
|
|
return &ans, settings, nil
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type Theme struct {
|
|
|
|
metadata *ThemeMetadata
|
|
|
|
|
2023-04-17 06:15:46 +03:00
|
|
|
code string
|
|
|
|
settings map[string]string
|
|
|
|
zip_reader *zip.File
|
|
|
|
is_user_defined bool
|
|
|
|
path_for_user_defined_theme string
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 19:01:09 +03:00
|
|
|
func (self *Theme) Name() string { return self.metadata.Name }
|
|
|
|
func (self *Theme) Author() string { return self.metadata.Author }
|
|
|
|
func (self *Theme) Blurb() string { return self.metadata.Blurb }
|
|
|
|
func (self *Theme) IsDark() bool { return self.metadata.Is_dark }
|
|
|
|
func (self *Theme) IsUserDefined() bool { return self.is_user_defined }
|
|
|
|
|
2023-02-27 05:30:13 +03:00
|
|
|
func (self *Theme) load_code() (string, error) {
|
2023-02-26 19:39:07 +03:00
|
|
|
if self.zip_reader != nil {
|
|
|
|
f, err := self.zip_reader.Open()
|
|
|
|
self.zip_reader = nil
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
data, err := io.ReadAll(f)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
self.code = utils.UnsafeBytesToString(data)
|
|
|
|
}
|
2023-04-17 06:15:46 +03:00
|
|
|
if self.is_user_defined && self.path_for_user_defined_theme != "" && self.code == "" {
|
|
|
|
raw, err := os.ReadFile(self.path_for_user_defined_theme)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
self.code = utils.UnsafeBytesToString(raw)
|
|
|
|
}
|
2023-02-26 19:39:07 +03:00
|
|
|
return self.code, nil
|
|
|
|
}
|
|
|
|
|
2023-03-11 07:44:03 +03:00
|
|
|
func (self *Theme) Code() (string, error) {
|
|
|
|
return self.load_code()
|
|
|
|
}
|
|
|
|
|
2023-03-13 19:01:09 +03:00
|
|
|
func (self *Theme) SaveInDir(dirpath string) (err error) {
|
|
|
|
path := filepath.Join(dirpath, self.Name()+".conf")
|
|
|
|
code, err := self.Code()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-22 12:31:19 +03:00
|
|
|
return utils.AtomicUpdateFile(path, bytes.NewReader(utils.UnsafeStringToBytes(code)), 0o644)
|
2023-03-13 19:01:09 +03:00
|
|
|
}
|
|
|
|
|
2023-03-11 07:44:03 +03:00
|
|
|
func (self *Theme) SaveInConf(config_dir, reload_in, config_file_name string) (err error) {
|
2023-09-18 18:08:08 +03:00
|
|
|
_ = os.MkdirAll(config_dir, 0o755)
|
2023-03-11 07:44:03 +03:00
|
|
|
path := filepath.Join(config_dir, `current-theme.conf`)
|
|
|
|
code, err := self.Code()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-22 12:31:19 +03:00
|
|
|
err = utils.AtomicUpdateFile(path, bytes.NewReader(utils.UnsafeStringToBytes(code)), 0o644)
|
2023-03-11 07:44:03 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-09-18 18:01:30 +03:00
|
|
|
confpath := config_file_name
|
|
|
|
if !filepath.IsAbs(config_file_name) {
|
|
|
|
confpath = filepath.Join(config_dir, config_file_name)
|
|
|
|
}
|
2024-05-18 10:15:55 +03:00
|
|
|
patcher := config.Patcher{Write_backup: true}
|
|
|
|
if _, err = patcher.Patch(
|
|
|
|
confpath, "KITTY_THEME", fmt.Sprintf("# %s\ninclude current-theme.conf", self.metadata.Name),
|
|
|
|
utils.Keys(AllColorSettingNames)...); err != nil {
|
|
|
|
return
|
2023-03-11 07:44:03 +03:00
|
|
|
}
|
2024-05-18 10:15:55 +03:00
|
|
|
switch reload_in {
|
|
|
|
case "parent":
|
|
|
|
config.ReloadConfigInKitty(true)
|
|
|
|
case "all":
|
|
|
|
config.ReloadConfigInKitty(false)
|
2023-03-11 07:44:03 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-27 05:30:13 +03:00
|
|
|
func (self *Theme) Settings() (map[string]string, error) {
|
|
|
|
if self.zip_reader != nil {
|
|
|
|
code, err := self.load_code()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
self.settings = make(map[string]string, 64)
|
2023-03-08 11:01:27 +03:00
|
|
|
scanner := utils.NewLineScanner(code)
|
2023-02-27 05:30:13 +03:00
|
|
|
for scanner.Scan() {
|
|
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
if line != "" && line[0] != '#' {
|
|
|
|
key, val, found := strings.Cut(line, " ")
|
|
|
|
if found {
|
|
|
|
self.settings[key] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self.settings, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Theme) AsEscapeCodes() (string, error) {
|
|
|
|
settings, err := self.Settings()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2023-03-13 19:01:09 +03:00
|
|
|
return ColorSettingsAsEscapeCodes(settings), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ColorSettingsAsEscapeCodes(settings map[string]string) string {
|
2023-02-27 05:30:13 +03:00
|
|
|
w := strings.Builder{}
|
|
|
|
w.Grow(4096)
|
|
|
|
|
|
|
|
set_color := func(i int, sharp string) {
|
|
|
|
w.WriteByte(';')
|
|
|
|
w.WriteString(strconv.Itoa(i))
|
|
|
|
w.WriteByte(';')
|
|
|
|
w.WriteString(sharp)
|
|
|
|
}
|
|
|
|
|
2023-03-18 12:44:31 +03:00
|
|
|
set_default_color := func(name, defval string, num loop.DefaultColor) {
|
2023-02-27 05:30:13 +03:00
|
|
|
w.WriteString("\033]")
|
|
|
|
defer func() { w.WriteString("\033\\") }()
|
|
|
|
val, found := settings[name]
|
|
|
|
if !found {
|
|
|
|
val = defval
|
|
|
|
}
|
|
|
|
if val != "" {
|
|
|
|
rgba, err := style.ParseColor(val)
|
|
|
|
if err == nil {
|
2023-03-18 12:44:31 +03:00
|
|
|
w.WriteString(strconv.Itoa(int(num)))
|
2023-02-27 05:30:13 +03:00
|
|
|
w.WriteByte(';')
|
|
|
|
w.WriteString(rgba.AsRGBSharp())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w.WriteByte('1')
|
2023-03-18 12:44:31 +03:00
|
|
|
w.WriteString(strconv.Itoa(int(num)))
|
2023-02-27 05:30:13 +03:00
|
|
|
}
|
2023-03-18 12:44:31 +03:00
|
|
|
set_default_color("foreground", style.DefaultColors.Foreground, loop.FOREGROUND)
|
|
|
|
set_default_color("background", style.DefaultColors.Background, loop.BACKGROUND)
|
|
|
|
set_default_color("cursor", style.DefaultColors.Cursor, loop.CURSOR)
|
|
|
|
set_default_color("selection_background", style.DefaultColors.SelectionBg, loop.SELECTION_BG)
|
|
|
|
set_default_color("selection_foreground", style.DefaultColors.SelectionFg, loop.SELECTION_FG)
|
2023-02-27 05:30:13 +03:00
|
|
|
|
2023-02-28 09:38:55 +03:00
|
|
|
w.WriteString("\033]4")
|
2023-02-27 05:30:13 +03:00
|
|
|
for i := 0; i < 256; i++ {
|
|
|
|
key := "color" + strconv.Itoa(i)
|
|
|
|
val := settings[key]
|
|
|
|
if val != "" {
|
|
|
|
rgba, err := style.ParseColor(val)
|
|
|
|
if err == nil {
|
|
|
|
set_color(i, rgba.AsRGBSharp())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rgba := style.RGBA{}
|
|
|
|
rgba.FromRGB(style.ColorTable[i])
|
|
|
|
set_color(i, rgba.AsRGBSharp())
|
|
|
|
}
|
|
|
|
w.WriteString("\033\\")
|
2023-03-13 19:01:09 +03:00
|
|
|
return w.String()
|
2023-02-27 05:30:13 +03:00
|
|
|
}
|
|
|
|
|
2023-02-26 18:10:59 +03:00
|
|
|
type Themes struct {
|
|
|
|
name_map map[string]*Theme
|
|
|
|
index_map []string
|
|
|
|
}
|
|
|
|
|
2023-03-12 06:38:26 +03:00
|
|
|
func (self *Themes) Copy() *Themes {
|
|
|
|
ans := &Themes{name_map: make(map[string]*Theme, len(self.name_map)), index_map: slices.Clone(self.index_map)}
|
|
|
|
maps.Copy(ans.name_map, self.name_map)
|
|
|
|
return ans
|
|
|
|
}
|
|
|
|
|
2023-08-09 09:38:42 +03:00
|
|
|
var camel_case_pat = sync.OnceValue(func() *regexp.Regexp {
|
2023-02-26 18:46:29 +03:00
|
|
|
return regexp.MustCompile(`([a-z])([A-Z])`)
|
2023-05-26 20:12:07 +03:00
|
|
|
})
|
2023-02-26 18:10:59 +03:00
|
|
|
|
2023-05-04 07:56:18 +03:00
|
|
|
func ThemeNameFromFileName(fname string) string {
|
2023-02-26 18:10:59 +03:00
|
|
|
fname = fname[:len(fname)-len(path.Ext(fname))]
|
|
|
|
fname = strings.ReplaceAll(fname, "_", " ")
|
|
|
|
fname = camel_case_pat().ReplaceAllString(fname, "$1 $2")
|
2023-08-07 19:19:50 +03:00
|
|
|
return strings.Join(utils.Map(strings.Title, strings.Split(fname, " ")), " ")
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
|
2023-03-12 06:38:26 +03:00
|
|
|
func (self *Themes) Len() int { return len(self.name_map) }
|
2023-03-13 19:01:09 +03:00
|
|
|
func (self *Themes) At(x int) *Theme {
|
|
|
|
if x >= len(self.index_map) || x < 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return self.name_map[self.index_map[x]]
|
|
|
|
}
|
|
|
|
func (self *Themes) Names() []string { return self.index_map }
|
|
|
|
|
2023-03-14 17:54:21 +03:00
|
|
|
func (self *Themes) create_index_map() {
|
2024-05-04 12:04:40 +03:00
|
|
|
self.index_map = utils.Keys(self.name_map)
|
2023-03-14 17:54:21 +03:00
|
|
|
self.index_map = utils.StableSortWithKey(self.index_map, strings.ToLower)
|
|
|
|
}
|
|
|
|
|
2023-03-13 19:01:09 +03:00
|
|
|
func (self *Themes) Filtered(is_ok func(*Theme) bool) *Themes {
|
2024-05-04 12:04:40 +03:00
|
|
|
themes := utils.Filter(utils.Values(self.name_map), is_ok)
|
2023-03-13 19:01:09 +03:00
|
|
|
ans := Themes{name_map: make(map[string]*Theme, len(themes))}
|
|
|
|
for _, theme := range themes {
|
|
|
|
ans.name_map[theme.metadata.Name] = theme
|
|
|
|
}
|
2023-03-14 17:54:21 +03:00
|
|
|
ans.create_index_map()
|
2023-03-13 19:01:09 +03:00
|
|
|
return &ans
|
|
|
|
}
|
2023-03-12 06:38:26 +03:00
|
|
|
|
2023-02-28 09:38:55 +03:00
|
|
|
func (self *Themes) AddFromFile(path string) (*Theme, error) {
|
2023-05-04 07:44:58 +03:00
|
|
|
m, conf, err := ParseThemeMetadata(path)
|
2023-02-28 09:38:55 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if m.Name == "" {
|
2023-05-04 07:56:18 +03:00
|
|
|
m.Name = ThemeNameFromFileName(filepath.Base(path))
|
2023-02-28 09:38:55 +03:00
|
|
|
}
|
2023-04-17 06:15:46 +03:00
|
|
|
t := Theme{metadata: m, is_user_defined: true, settings: conf, path_for_user_defined_theme: path}
|
2023-02-28 09:38:55 +03:00
|
|
|
self.name_map[m.Name] = &t
|
|
|
|
return &t, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-26 18:10:59 +03:00
|
|
|
func (self *Themes) add_from_dir(dirpath string) error {
|
|
|
|
entries, err := os.ReadDir(dirpath)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, e := range entries {
|
|
|
|
if !e.IsDir() && strings.HasSuffix(e.Name(), ".conf") {
|
2023-04-17 05:32:41 +03:00
|
|
|
path := filepath.Join(dirpath, e.Name())
|
2023-04-17 05:37:26 +03:00
|
|
|
// ignore files if they are the STDOUT of the current processes
|
|
|
|
// allows using kitten theme --dump-theme name > ~/.config/kitty/themes/name.conf
|
|
|
|
if utils.Samefile(path, os.Stdout) {
|
2023-04-17 05:32:41 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, err = self.AddFromFile(path); err != nil {
|
2023-02-26 18:10:59 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-26 19:39:07 +03:00
|
|
|
func (self *Themes) add_from_zip_file(zippath string) (io.Closer, error) {
|
2023-02-26 18:10:59 +03:00
|
|
|
r, err := zip.OpenReader(zippath)
|
|
|
|
if err != nil {
|
2023-02-26 19:39:07 +03:00
|
|
|
return nil, err
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
name_map := make(map[string]*zip.File, len(r.File))
|
2023-03-11 07:44:03 +03:00
|
|
|
var themes []*ThemeMetadata
|
2023-02-26 18:10:59 +03:00
|
|
|
theme_dir := ""
|
|
|
|
for _, file := range r.File {
|
|
|
|
name_map[file.Name] = file
|
|
|
|
if path.Base(file.Name) == "themes.json" {
|
|
|
|
theme_dir = path.Dir(file.Name)
|
|
|
|
fr, err := file.Open()
|
|
|
|
if err != nil {
|
2023-02-26 19:39:07 +03:00
|
|
|
return nil, fmt.Errorf("Error while opening %s from the ZIP file: %w", file.Name, err)
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
defer fr.Close()
|
|
|
|
raw, err := io.ReadAll(fr)
|
|
|
|
if err != nil {
|
2023-02-26 19:39:07 +03:00
|
|
|
return nil, fmt.Errorf("Error while reading %s from the ZIP file: %w", file.Name, err)
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
err = json.Unmarshal(raw, &themes)
|
|
|
|
if err != nil {
|
2023-02-26 19:39:07 +03:00
|
|
|
return nil, fmt.Errorf("Error while decoding %s: %w", file.Name, err)
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if theme_dir == "" {
|
2023-02-26 19:39:07 +03:00
|
|
|
return nil, fmt.Errorf("No themes.json found in ZIP file")
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
for _, theme := range themes {
|
|
|
|
key := path.Join(theme_dir, theme.Filepath)
|
|
|
|
f := name_map[key]
|
|
|
|
if f != nil {
|
2023-03-11 07:44:03 +03:00
|
|
|
t := Theme{metadata: theme, zip_reader: f}
|
2023-02-26 18:10:59 +03:00
|
|
|
self.name_map[theme.Name] = &t
|
|
|
|
}
|
|
|
|
}
|
2023-02-26 19:39:07 +03:00
|
|
|
return r, nil
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
|
2023-02-26 19:39:07 +03:00
|
|
|
func (self *Themes) ThemeByName(name string) *Theme {
|
2023-03-11 07:44:03 +03:00
|
|
|
ans := self.name_map[name]
|
|
|
|
if ans == nil {
|
|
|
|
q := strings.ToLower(name)
|
|
|
|
for k, t := range self.name_map {
|
|
|
|
if strings.ToLower(k) == q {
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ans
|
2023-02-26 19:39:07 +03:00
|
|
|
}
|
|
|
|
|
2023-03-12 19:04:54 +03:00
|
|
|
func match(expression string, items []string) []*subseq.Match {
|
|
|
|
matches := subseq.ScoreItems(expression, items, subseq.Options{Level1: " "})
|
2023-08-04 20:20:13 +03:00
|
|
|
matches = utils.StableSort(matches, func(a, b *subseq.Match) int {
|
|
|
|
if b.Score < a.Score {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
if b.Score > a.Score {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
})
|
2023-03-12 19:04:54 +03:00
|
|
|
return matches
|
2023-03-12 06:38:26 +03:00
|
|
|
}
|
|
|
|
|
2023-03-13 19:01:09 +03:00
|
|
|
const (
|
|
|
|
MARK_BEFORE = "\033[33m"
|
|
|
|
MARK_AFTER = "\033[39m"
|
|
|
|
)
|
|
|
|
|
2023-03-12 06:38:26 +03:00
|
|
|
func (self *Themes) ApplySearch(expression string, marks ...string) []string {
|
2023-03-13 19:01:09 +03:00
|
|
|
mark_before, mark_after := MARK_BEFORE, MARK_AFTER
|
2023-03-12 06:38:26 +03:00
|
|
|
if len(marks) == 2 {
|
|
|
|
mark_before, mark_after = marks[0], marks[1]
|
|
|
|
}
|
2023-03-14 17:54:21 +03:00
|
|
|
results := utils.Filter(match(expression, self.index_map), func(x *subseq.Match) bool { return x.Score > 0 })
|
2023-03-12 06:38:26 +03:00
|
|
|
name_map := make(map[string]*Theme, len(results))
|
2023-03-14 17:54:21 +03:00
|
|
|
for _, m := range results {
|
|
|
|
name_map[m.Text] = self.name_map[m.Text]
|
|
|
|
}
|
|
|
|
self.name_map = name_map
|
|
|
|
self.index_map = self.index_map[:0]
|
2023-03-12 06:38:26 +03:00
|
|
|
ans := make([]string, 0, len(results))
|
2023-03-12 19:04:54 +03:00
|
|
|
for _, m := range results {
|
|
|
|
text := m.Text
|
|
|
|
positions := m.Positions
|
|
|
|
for i := len(positions) - 1; i >= 0; i-- {
|
|
|
|
p := positions[i]
|
|
|
|
text = text[:p] + mark_before + text[p:p+1] + mark_after + text[p+1:]
|
2023-03-12 06:38:26 +03:00
|
|
|
}
|
2023-03-12 19:04:54 +03:00
|
|
|
ans = append(ans, text)
|
2023-03-14 17:54:21 +03:00
|
|
|
self.index_map = append(self.index_map, m.Text)
|
2023-03-12 06:38:26 +03:00
|
|
|
}
|
|
|
|
return ans
|
|
|
|
}
|
|
|
|
|
2023-02-28 09:38:55 +03:00
|
|
|
func LoadThemes(cache_age time.Duration) (ans *Themes, closer io.Closer, err error) {
|
2023-02-26 19:39:07 +03:00
|
|
|
zip_path, err := FetchCached(cache_age)
|
|
|
|
ans = &Themes{name_map: make(map[string]*Theme)}
|
2023-02-26 18:10:59 +03:00
|
|
|
if err != nil {
|
2023-02-28 09:38:55 +03:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
if closer, err = ans.add_from_zip_file(zip_path); err != nil {
|
|
|
|
return nil, nil, err
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
|
|
|
if err = ans.add_from_dir(filepath.Join(utils.ConfigDir(), "themes")); err != nil {
|
2023-02-26 19:39:07 +03:00
|
|
|
return nil, nil, err
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
2023-03-14 17:54:21 +03:00
|
|
|
ans.create_index_map()
|
2023-02-26 19:39:07 +03:00
|
|
|
return ans, closer, nil
|
2023-02-26 18:10:59 +03:00
|
|
|
}
|
2023-02-28 09:38:55 +03:00
|
|
|
|
|
|
|
func ThemeFromFile(path string) (*Theme, error) {
|
|
|
|
ans := &Themes{name_map: make(map[string]*Theme)}
|
|
|
|
return ans.AddFromFile(path)
|
|
|
|
}
|
2023-03-11 07:44:03 +03:00
|
|
|
|
|
|
|
func GetThemeNames(cache_age time.Duration) (ans []string, err error) {
|
|
|
|
themes, closer, err := LoadThemes(cache_age)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, ErrNoCacheFound) {
|
|
|
|
return []string{"Default"}, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer closer.Close()
|
|
|
|
for name := range themes.name_map {
|
|
|
|
ans = append(ans, name)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func CompleteThemes(completions *cli.Completions, word string, arg_num int) {
|
|
|
|
names, err := GetThemeNames(-1)
|
2023-03-14 18:10:12 +03:00
|
|
|
if err == nil {
|
2023-03-11 07:44:03 +03:00
|
|
|
mg := completions.AddMatchGroup("Themes")
|
|
|
|
for _, theme_name := range names {
|
|
|
|
theme_name = strings.TrimSpace(theme_name)
|
|
|
|
if theme_name != "" && strings.HasPrefix(theme_name, word) {
|
|
|
|
mg.AddMatch(theme_name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|