turbo-editors/turbo-corepublic Fork 0
v1.0.2
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

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