| 🛟 Updated. 28d5985 k33g 21h ago | 1 | package theme_test |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 📦 Turbo Core f3ade8d k33g 13h ago | 6 | "rickub.com/turbo-editors/turbo-core/theme" |
| 🛟 Updated. 28d5985 k33g 21h ago | 7 | ) |
| 8 | |
| 9 | // Reading a style out of a theme, and the fallback that makes a partial theme |
| 10 | // usable. |
| 11 | func 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. |
| 36 | func 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 | } |