Files
cheat/vendor/github.com/alecthomas/chroma/v2/styles/api.go
dependabot[bot] b40cc1e04e chore(deps): bump github.com/alecthomas/chroma/v2 from 2.23.1 to 2.24.1
Bumps [github.com/alecthomas/chroma/v2](https://github.com/alecthomas/chroma) from 2.23.1 to 2.24.1.
- [Release notes](https://github.com/alecthomas/chroma/releases)
- [Commits](https://github.com/alecthomas/chroma/compare/v2.23.1...v2.24.1)

---
updated-dependencies:
- dependency-name: github.com/alecthomas/chroma/v2
  dependency-version: 2.24.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-30 22:11:51 +00:00

67 lines
1.2 KiB
Go

package styles
import (
"embed"
"io/fs"
"sort"
"strings"
"github.com/alecthomas/chroma/v2"
)
//go:embed *.xml
var embedded embed.FS
// Registry of Styles.
var Registry = func() map[string]*chroma.Style {
registry := map[string]*chroma.Style{}
// Register all embedded styles.
files, err := fs.ReadDir(embedded, ".")
if err != nil {
panic(err)
}
for _, file := range files {
if file.IsDir() {
continue
}
r, err := embedded.Open(file.Name())
if err != nil {
panic(err)
}
style, err := chroma.NewXMLStyle(r)
if err != nil {
panic(err)
}
registry[strings.ToLower(style.Name)] = style
_ = r.Close()
}
return registry
}()
// Fallback style. Reassign to change the default fallback style.
var Fallback = Registry["swapoff"]
// Register a chroma.Style.
func Register(style *chroma.Style) *chroma.Style {
Registry[strings.ToLower(style.Name)] = style
return style
}
// Names of all available styles.
func Names() []string {
out := []string{}
for name := range Registry {
out = append(out, name)
}
sort.Strings(out)
return out
}
// Get named style, or Fallback.
func Get(name string) *chroma.Style {
if style, ok := Registry[strings.ToLower(name)]; ok {
return style
}
return Fallback
}