turbo-editors/turbo-corepublic Fork 0
v1.0.1
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.

📦 Turbo Core f3ade8d · on v1.0.1 · k33g · 11h ago
example_test.go · 50 lines · 1.1 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
45
46
47
48
49
50
package ui_test

import (
	"fmt"

	"rickub.com/turbo-editors/turbo-core/ui"
)

// Building a menu, the way the editor's File menu is put together.
func ExampleNewMenuBar() {
	bar := ui.NewMenuBar(&ui.Menu{
		Label: "~F~ile",
		Items: []*ui.MenuItem{
			{Label: "~O~pen…", Shortcut: "F3", Action: func() {}},
			{Separator: true},
			{Label: "E~x~it", Shortcut: "Alt-X", Action: func() {}},
		},
	})

	fmt.Println(bar.Open())
	bar.OpenMenu(0)
	fmt.Println(bar.Open())
	// Output:
	// false
	// true
}

// Hot keys are written with tildes and read back with SplitHotKey.
func ExampleSplitHotKey() {
	text, key, index := ui.SplitHotKey("Save ~A~s…")

	fmt.Printf("%q %c %d\n", text, key, index)
	fmt.Println(ui.MatchesHotKey("Save ~A~s…", 'A'))
	// Output:
	// "Save As…" a 5
	// true
}

// A rectangle is placed and clipped with plain geometry; the painter does the
// rest.
func ExampleRect() {
	screen := ui.Rect{W: 80, H: 24}
	dialog := ui.Rect{W: 40, H: 10}.CenteredIn(screen)

	fmt.Printf("%+v\n", dialog)
	fmt.Printf("%+v\n", dialog.Inset(1, 1))
	// Output:
	// {X:20 Y:7 W:40 H:10}
	// {X:21 Y:8 W:38 H:8}
}