package theme import ( "embed" "fmt" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/styles" ) //go:embed themes/* var themeFS embed.FS // RegisterAll: Registers all XML theme files embedded in the themes/ directory // with chroma's style registry. After calling this, styles.Get() will recognize // any theme defined in those files. func RegisterAll() error { entries, err := themeFS.ReadDir("themes") if err != nil { return fmt.Errorf("failed to read embedded themes directory: %w", err) } for _, entry := range entries { if entry.IsDir() { continue } f, err := themeFS.Open("themes/" + entry.Name()) if err != nil { return fmt.Errorf("failed to open theme %s: %w", entry.Name(), err) } style, err := chroma.NewXMLStyle(f) f.Close() if err != nil { return fmt.Errorf("failed to parse theme %s: %w", entry.Name(), err) } styles.Register(style) } return nil }