turbo-editors/turbo-corepublic Fork 0
v0.9.0
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.

🛟 Updated. 28d5985 · on v0.9.0 · k33g · 15h ago
example_test.go · 44 lines · 1.0 KBGo Blame HistoryRaw
 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())
	}
}