1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package theme_test
import (
"fmt"
"codeberg.org/turbo-editors/turbo-core/theme"
)
// Reading a style out of a theme, and the fallback that makes a partial theme
// usable.
func ExampleTheme_Style() {
th, err := theme.Parse([]byte(`
name = "Minimal"
[colors]
default = { fg = "white", bg = "navy" }
syntax = { fg = "aqua" }
`), "")
if err != nil {
panic(err)
}
// "syntax.keyword" is not set, so the lookup walks up to "syntax".
fg, bg, _ := th.Style(theme.KeySyntaxKeyword).Decompose()
fmt.Println(fg, bg)
// Nothing matches "menu.bar" at all, so it lands on "default".
fg, _, _ = th.Style(theme.KeyMenuBar).Decompose()
fmt.Println(fg)
// Output:
// aqua navy
// white
}
// Listing what the user can choose from in the Options menu. The directory is
// where the user's own themes live; "" offers the embedded ones alone.
func ExampleAvailable() {
for _, name := range theme.Available("") {
th, err := theme.Load(name, "")
if err != nil {
continue
}
fmt.Printf("%s — %s\n", name, th.Name())
}
}
|