66
|
1 package styles
|
|
2
|
|
3 import (
|
|
4 "sort"
|
|
5
|
|
6 "github.com/alecthomas/chroma/v2"
|
|
7 )
|
|
8
|
|
9 // Registry of Styles.
|
|
10 var Registry = map[string]*chroma.Style{}
|
|
11
|
|
12 // Fallback style. Reassign to change the default fallback style.
|
|
13 var Fallback = SwapOff
|
|
14
|
|
15 // Register a chroma.Style.
|
|
16 func Register(style *chroma.Style) *chroma.Style {
|
|
17 Registry[style.Name] = style
|
|
18 return style
|
|
19 }
|
|
20
|
|
21 // Names of all available styles.
|
|
22 func Names() []string {
|
|
23 out := []string{}
|
|
24 for name := range Registry {
|
|
25 out = append(out, name)
|
|
26 }
|
|
27 sort.Strings(out)
|
|
28 return out
|
|
29 }
|
|
30
|
|
31 // Get named style, or Fallback.
|
|
32 func Get(name string) *chroma.Style {
|
|
33 if style, ok := Registry[name]; ok {
|
|
34 return style
|
|
35 }
|
|
36 return Fallback
|
|
37 }
|