mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-11 14:45:31 +03:00
Entry point for parsing theme metadata
This commit is contained in:
parent
8ba7258db9
commit
3eb18a416a
@ -3,7 +3,10 @@
|
||||
package themes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -96,3 +99,45 @@ func main(_ *cli.Command, opts *Options, args []string) (rc int, err error) {
|
||||
func EntryPoint(parent *cli.Command) {
|
||||
create_cmd(parent, main)
|
||||
}
|
||||
|
||||
func parse_theme_metadata() error {
|
||||
raw, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
paths := utils.Splitlines(utils.UnsafeBytesToString(raw))
|
||||
ans := make([]*themes.ThemeMetadata, 0, len(paths))
|
||||
for _, path := range paths {
|
||||
if path != "" {
|
||||
metadata, _, err := themes.ParseThemeMetadata(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ans = append(ans, metadata)
|
||||
}
|
||||
}
|
||||
raw, err = json.Marshal(ans)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = os.Stdout.Write(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParseEntryPoint(parent *cli.Command) {
|
||||
parent.AddSubCommand(&cli.Command{
|
||||
Name: "__parse_theme_metadata__",
|
||||
Hidden: true,
|
||||
Run: func(cmd *cli.Command, args []string) (rc int, err error) {
|
||||
err = parse_theme_metadata()
|
||||
if err != nil {
|
||||
rc = 1
|
||||
}
|
||||
return
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ func KittyToolEntryPoints(root *cli.Command) {
|
||||
diff.EntryPoint(root)
|
||||
// themes
|
||||
themes.EntryPoint(root)
|
||||
themes.ParseEntryPoint(root)
|
||||
// __pytest__
|
||||
pytest.EntryPoint(root)
|
||||
// __hold_till_enter__
|
||||
|
@ -463,7 +463,7 @@ type ThemeMetadata struct {
|
||||
Author string `json:"author"`
|
||||
}
|
||||
|
||||
func parse_theme_metadata(path string) (*ThemeMetadata, map[string]string, error) {
|
||||
func ParseThemeMetadata(path string) (*ThemeMetadata, map[string]string, error) {
|
||||
var in_metadata, in_blurb, finished_metadata bool
|
||||
ans := ThemeMetadata{}
|
||||
settings := map[string]string{}
|
||||
@ -816,7 +816,7 @@ func (self *Themes) Filtered(is_ok func(*Theme) bool) *Themes {
|
||||
}
|
||||
|
||||
func (self *Themes) AddFromFile(path string) (*Theme, error) {
|
||||
m, conf, err := parse_theme_metadata(path)
|
||||
m, conf, err := ParseThemeMetadata(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user