-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_page_test.go
More file actions
209 lines (180 loc) · 4.58 KB
/
Copy pathstart_page_test.go
File metadata and controls
209 lines (180 loc) · 4.58 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package glyph_test
// compiler-verified examples matching the start.html code blocks.
// if these break, the getting started page is lying.
import (
"fmt"
"testing"
. "github.com/kungfusheep/glyph"
)
type startTask struct {
Title string
Done bool
Priority int
}
// start.html: section 02, first app (counter)
func TestStart_firstApp(t *testing.T) {
app := NewApp()
count := 0
app.SetView(
VBox(
Text(&count),
Text("up/down to count, q to quit"),
),
)
app.Handle("<Up>", func() { count++ })
app.Handle("<Down>", func() { count-- })
app.Handle("q", app.Stop)
_ = app
}
// start.html: section 03, lists with render
func TestStart_listRender(t *testing.T) {
app := NewApp()
tasks := []startTask{
{"Write tutorial", false, 0},
{"Add tests", false, 0},
{"Ship it", false, 0},
}
app.SetView(
VBox(
Text("Tasks").Bold(),
List(&tasks).Render(func(t *startTask) Component {
return HBox.Gap(1)(
If(&t.Done).Then(Text("[x]")).Else(Text("[ ]")),
Text(&t.Title),
)
}).BindVimNav(),
),
)
app.Handle("q", app.Stop)
_ = app
}
// start.html: section 03, filter list
func TestStart_filterList(t *testing.T) {
tasks := []startTask{
{"Write tutorial", false, 0},
}
_ = FilterList(&tasks, func(t *startTask) string { return t.Title }).
Render(func(t *startTask) Component {
return Text(&t.Title)
}).MaxVisible(10).Border(BorderRounded)
}
// start.html: section 04, layout split pane
func TestStart_layoutSplitPane(t *testing.T) {
_ = HBox(
VBox.Grow(1).Border(BorderRounded).Title("left")(
Text("panel one"),
),
VBox.Grow(2).Border(BorderRounded).Title("right")(
Text("panel two takes 2/3 width"),
),
)
}
// start.html: section 04, status bar with gaps
func TestStart_statusBar(t *testing.T) {
_ = HBox.Gap(2)(
Text("ready").FG(Green),
Text("3 tasks").Bold(),
Space(),
Text("q: quit").FG(BrightBlack),
)
}
// start.html: section 04, full split-pane app
func TestStart_fullSplitApp(t *testing.T) {
app := NewApp()
tasks := []startTask{
{"Write tutorial", false, 1},
{"Add tests", true, 2},
{"Ship it", false, 3},
}
detail := "select a task"
app.SetView(
VBox(
Text("Task Manager").Bold(),
HBox(
VBox.Grow(1).Border(BorderRounded).Title("tasks")(
List(&tasks).Render(func(t *startTask) Component {
return HBox.Gap(1)(
If(&t.Done).Then(Text("[x]")).Else(Text("[ ]")),
Text(&t.Title),
)
}).OnSelect(func(t *startTask) {
detail = fmt.Sprintf("%s (priority: %d)", t.Title, t.Priority)
}).BindVimNav(),
),
VBox.Grow(1).Border(BorderRounded).Title("detail")(
Text(&detail),
),
),
HBox.Gap(2)(
Text("j/k: navigate").FG(BrightBlack),
Text("q: quit").FG(BrightBlack),
),
),
)
app.Handle("q", app.Stop)
_ = app
}
// start.html: section 05, keyboard list handle
func TestStart_keyboardListHandle(t *testing.T) {
tasks := []startTask{
{"Write tutorial", false, 0},
}
_ = List(&tasks).Render(func(t *startTask) Component {
return HBox.Gap(1)(
If(&t.Done).Then(Text("[x]")).Else(Text("[ ]")),
Text(&t.Title),
)
}).Handle("<Space>", func(t *startTask) {
t.Done = !t.Done
}).BindVimNav()
}
// start.html: section 05, autotable bind nav
func TestStart_autoTableBindNav(t *testing.T) {
type proc struct {
PID int
CPU float64
}
var procs []proc
_ = AutoTable(&procs).Scrollable(20).
BindNav("<C-n>", "<C-p>").
BindPageNav("<C-d>", "<C-u>")
}
// start.html: section 06, inline styling
func TestStart_inlineStyling(t *testing.T) {
_ = Text("error").FG(Red).Bold()
_ = Text("muted").FG(BrightBlack).Dim()
_ = Text("success").FG(Green)
_ = Text("warning").FG(Yellow).Bold()
}
// start.html: section 06, hex/rgb colours
func TestStart_hexRgb(t *testing.T) {
_ = Text("branded").FG(Hex(0xc44040))
_ = Text("custom").BG(RGB(20, 20, 40))
}
// start.html: section 06, cascade style theme
func TestStart_cascadeTheme(t *testing.T) {
theme := ThemeDark
_ = VBox.CascadeStyle(&theme.Base).Border(BorderRounded).BorderFG(theme.Border.FG)(
Text("normal text"),
Text("muted").Style(theme.Muted),
Text("accent").Style(theme.Accent),
Text("error!").Style(theme.Error),
)
}
// start.html: section 06, custom theme
func TestStart_customTheme(t *testing.T) {
myTheme := ThemeEx{
Base: Style{FG: White},
Muted: Style{FG: BrightBlack},
Accent: Style{FG: Cyan, Attr: AttrBold},
Error: Style{FG: Red},
Border: Style{FG: BrightBlack},
}
_ = myTheme
}
// start.html: section 06, border colours
func TestStart_borderColours(t *testing.T) {
_ = VBox.Border(BorderRounded).BorderFG(Cyan).Title("status")(
Text("all systems go").FG(Green),
)
}