-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
452 lines (427 loc) · 12.9 KB
/
main.go
File metadata and controls
452 lines (427 loc) · 12.9 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
package main
import (
"context"
"errors"
"flag"
"fmt"
tea "charm.land/bubbletea/v2"
"github.com/flowexec/tuikit"
sampleTypes "github.com/flowexec/tuikit/sample/types"
"github.com/flowexec/tuikit/themes"
"github.com/flowexec/tuikit/types"
"github.com/flowexec/tuikit/views"
)
func main() {
var viewType string
flag.StringVar(&viewType, "view", "frame", "view type")
flag.Parse()
ctx := context.Background()
app := &tuikit.Application{Name: "tuikit-sample", Version: "v1"}
container, err := tuikit.NewContainer(ctx, app)
if err != nil {
panic(err)
}
if err := container.Start(); err != nil {
panic(err)
}
view := buildView(viewType, container)
if err := container.SetView(view); err != nil {
panic(err)
}
container.WaitForExit()
}
func buildView(viewType string, container *tuikit.Container) tuikit.View {
var view tuikit.View
switch viewType {
case "frame":
inner := &sampleTypes.Echo{
Content: "You are currently viewing a rendered frame. " +
"Use the --view flag to switch to a different view.",
}
view = views.NewFrameView(inner)
case "loading":
view = views.NewLoadingView(
"waiting for the paint to dry...",
container.RenderState().Theme,
)
case "error":
view = views.NewErrorView(
errors.New("something went wrong - please try again"),
container.RenderState().Theme,
)
case "markdown":
md := "# Hmmm...\n\n > To be, or not to be, " +
"**that is the question**.\n> *William Shakespeare*"
view = views.NewMarkdownView(container.RenderState(), md)
case "entity":
e := &sampleTypes.Thing{Name: "William Shakespeare", Type: "Author"}
view = views.NewEntityView(
container.RenderState(), e, types.EntityFormatDocument,
)
case "collection":
view = buildCollectionView(container)
case "detail":
view = buildDetailView(container)
case "detail-content":
view = buildDetailContentView(container)
case "table":
view = buildTableFullView(container)
case "table-mini":
view = buildTableMiniView(container)
case "table-mini-multi":
view = buildTableMiniMultiView(container)
case "form":
view = buildFormView(container)
case "library":
view = buildLibraryView(container)
}
return view
}
func buildDetailView(container *tuikit.Container) tuikit.View {
body := `2026-03-30 14:22:01 [INFO] deploy-pipeline read secret DATABASE_URL
2026-03-30 08:15:33 [INFO] api-server read secret DATABASE_URL
2026-03-29 22:00:00 [WARN] rotation check: 75 days remaining
2026-03-28 16:45:12 [INFO] api-server read secret DATABASE_URL
2026-03-28 09:30:00 [INFO] deploy-pipeline read secret DATABASE_URL`
return views.NewDetailView(
container.RenderState(),
body,
views.DetailField{Key: "Name", Value: "DATABASE_URL"},
views.DetailField{Key: "Environment", Value: "production"},
views.DetailField{Key: "Created", Value: "2026-01-15 10:30:00"},
views.DetailField{Key: "Rotation", Value: "90 days"},
)
}
func buildDetailContentView(container *tuikit.Container) tuikit.View {
body := "# Detail Content View\n\n" +
"This is an example of the **DetailContent** view. " +
"It supports markdown formatting (via *glamour*), " +
"a formatted header, and structured key-value metadata.\n\n" +
"### Example Code\n\n" +
"```go\n" +
"package main\n\n" +
"import \"fmt\"\n\n" +
"func main() {\n" +
"\tfmt.Println(\"Hello tuikit!\")\n" +
"}\n" +
"```\n"
opts := views.DetailContentOpts{
Title: "Sample Detail Content",
Subtitle: "Component Demonstration",
Metadata: []views.DetailField{
{Key: "Component", Value: "DetailContentView"},
{Key: "Package", Value: "tuikit/views"},
{Key: "Status", Value: "Experimental"},
},
Body: body,
Footer: "Rendered to showcase DetailContentView",
}
return views.NewDetailContentView(
container.RenderState(),
opts,
types.KeyCallback{
Key: "enter", Label: "submit", Callback: func() error {
container.SetNotice("Acknowledged!", themes.OutputLevelSuccess)
return nil
},
},
)
}
func buildCollectionView(container *tuikit.Container) tuikit.View {
c := sampleTypes.NewThingList("Author",
&types.EntityInfo{
ID: "william", Header: "William Shakespeare",
SubHeader: "English Playwright",
},
&types.EntityInfo{
ID: "jane", Header: "Jane Austen",
SubHeader: "English Novelist",
},
&types.EntityInfo{
ID: "mark", Header: "Mark Twain",
SubHeader: "American Author",
},
)
return views.NewCollectionView(
container.RenderState(), c, types.CollectionFormatList, nil,
)
}
func buildTableFullView(container *tuikit.Container) tuikit.View {
columns := []views.TableColumn{
{Title: "Workspace", Percentage: 40},
{Title: "Description", Percentage: 35},
{Title: "Status", Percentage: 25},
}
rows := []views.TableRow{
{
Data: []string{"flow-workspace", "Main development workspace", "Active"},
Children: []views.TableRow{
{Data: []string{"docs", "", "5 exec"}},
{Data: []string{"api", "", "12 exec"}},
{Data: []string{"frontend", "", "8 exec"}},
},
},
{
Data: []string{"home-lab", "Infrastructure automation", "Inactive"},
Children: []views.TableRow{
{Data: []string{"k8s", "", "15 exec"}},
{Data: []string{"monitoring", "", "6 exec"}},
},
},
{
Data: []string{"personal-tools", "Personal utility scripts", "Active"},
Children: []views.TableRow{},
},
}
table := views.NewTable(
container.RenderState(), columns, rows, views.TableDisplayFull,
)
table.SetOnSelect(func(index int) error {
selectedRow := table.GetSelectedRow()
if selectedRow != nil {
container.SetNotice(
fmt.Sprintf("Selected: %s", selectedRow.Data()[0]),
themes.OutputLevelInfo,
)
}
return nil
})
table.SetOnHover(func(index int) {
selectedRow := table.GetSelectedRow()
if selectedRow != nil {
container.SetState("Current", selectedRow.Data()[0])
}
})
return table
}
func buildTableMiniView(container *tuikit.Container) tuikit.View {
columns := []views.TableColumn{
{Title: "Available Executables", Percentage: 100},
}
rows := []views.TableRow{
{Data: []string{"build app"}},
{Data: []string{"test unit"}},
{Data: []string{"deploy staging"}},
{Data: []string{"deploy production"}},
{Data: []string{"clean artifacts"}},
}
table := views.NewTable(
container.RenderState(), columns, rows, views.TableDisplayMini,
)
table.SetOnSelect(func(index int) error {
selectedRow := table.GetSelectedRow()
if selectedRow != nil {
container.SetNotice(
fmt.Sprintf("Executing: %s", selectedRow.Data()[0]),
themes.OutputLevelInfo,
)
}
return nil
})
return table
}
func buildTableMiniMultiView(container *tuikit.Container) tuikit.View {
columns := []views.TableColumn{
{Title: "Template", Percentage: 60},
{Title: "Type", Percentage: 40},
}
rows := []views.TableRow{
{Data: []string{"k8s-deployment", "Kubernetes"}},
{Data: []string{"react-app", "Frontend"}},
{Data: []string{"go-service", "Backend"}},
{Data: []string{"terraform-module", "Infrastructure"}},
}
table := views.NewTable(
container.RenderState(), columns, rows, views.TableDisplayMini,
)
table.SetOnSelect(func(index int) error {
selectedRow := table.GetSelectedRow()
if selectedRow != nil {
msg := fmt.Sprintf(
"Selected template: %s (%s)",
selectedRow.Data()[0], selectedRow.Data()[1],
)
container.SetNotice(msg, themes.OutputLevelInfo)
}
return nil
})
return table
}
func buildLibraryView(container *tuikit.Container) tuikit.View {
return views.NewLibrary(
container.RenderState(),
libraryWorkspacePage(container),
libraryExecPage(container),
libraryEntityPage(container),
)
}
func libraryWorkspacePage(container *tuikit.Container) views.LibraryPage {
return views.LibraryPage{
Title: "Workspaces",
Factory: func(render *types.RenderState, _ []views.PageSelection) (tea.Model, []types.KeyCallback) {
columns := []views.TableColumn{
{Title: "Workspace", Percentage: 40},
{Title: "Description", Percentage: 35},
{Title: "Status", Percentage: 25},
}
rows := []views.TableRow{
{
Data: []string{"flow-workspace", "Main development workspace", "Active"},
Children: []views.TableRow{
{Data: []string{"docs", "Documentation namespace", "5 executables"}},
{Data: []string{"api", "API services", "12 executables"}},
{Data: []string{"frontend", "Web UI components", "8 executables"}},
},
},
{
Data: []string{"home-lab", "Infrastructure automation", "Active"},
Children: []views.TableRow{
{Data: []string{"k8s", "Kubernetes configs", "15 executables"}},
{Data: []string{"monitoring", "Observability stack", "6 executables"}},
},
},
{
Data: []string{"personal-tools", "Personal utility scripts", "Active"},
Children: []views.TableRow{},
},
}
table := views.NewTable(render, columns, rows, views.TableDisplayFull)
keys := []types.KeyCallback{
{Key: "o", Label: "open", Callback: func() error {
container.SetNotice("Opening workspace folder...", themes.OutputLevelInfo)
return nil
}},
{Key: "s", Label: "set context", Callback: func() error {
container.SetNotice("Context updated", themes.OutputLevelSuccess)
return nil
}},
}
return table, keys
},
}
}
func libraryExecPage(container *tuikit.Container) views.LibraryPage {
return views.LibraryPage{
Title: "Executables",
Factory: func(render *types.RenderState, selections []views.PageSelection) (tea.Model, []types.KeyCallback) {
ws := selections[0].Data[0]
columns := []views.TableColumn{
{Title: "Executable", Percentage: 40},
{Title: "Verb", Percentage: 20},
{Title: "Tags", Percentage: 40},
}
execsByWs := map[string][]views.TableRow{
"flow-workspace": {
{Data: []string{"build-app", "exec", "go, build"}},
{Data: []string{"test-unit", "exec", "go, test"}},
{Data: []string{"test-integration", "exec", "go, test, integration"}},
{Data: []string{"deploy-staging", "exec", "deploy, staging"}},
{Data: []string{"deploy-prod", "exec", "deploy, production"}},
{Data: []string{"lint-check", "exec", "go, lint"}},
{Data: []string{"gen-docs", "exec", "docs, generate"}},
},
"home-lab": {
{Data: []string{"apply-k8s", "exec", "kubernetes, apply"}},
{Data: []string{"sync-configs", "exec", "kubernetes, sync"}},
{Data: []string{"restart-pods", "exec", "kubernetes, restart"}},
{Data: []string{"check-alerts", "exec", "monitoring, alerts"}},
},
"personal-tools": {
{Data: []string{"backup-dotfiles", "exec", "backup, dotfiles"}},
{Data: []string{"update-deps", "exec", "maintenance"}},
},
}
rows := execsByWs[ws]
if rows == nil {
rows = []views.TableRow{}
}
table := views.NewTable(render, columns, rows, views.TableDisplayFull)
keys := []types.KeyCallback{
{Key: "r", Label: "run", Callback: func() error {
sel := table.GetSelectedRow()
if sel != nil {
container.SetNotice(
fmt.Sprintf("Running: %s/%s", ws, sel.Data()[0]),
themes.OutputLevelInfo,
)
}
return nil
}},
{Key: "c", Label: "copy ref", Callback: func() error {
sel := table.GetSelectedRow()
if sel != nil {
container.SetNotice(
fmt.Sprintf("Copied: %s/%s", ws, sel.Data()[0]),
themes.OutputLevelSuccess,
)
}
return nil
}},
}
return table, keys
},
}
}
func libraryEntityPage(container *tuikit.Container) views.LibraryPage {
return views.LibraryPage{
Title: "Details",
Factory: func(render *types.RenderState, selections []views.PageSelection) (tea.Model, []types.KeyCallback) {
ws := selections[0].Data[0]
exec := selections[1].Data[0]
entity := &sampleTypes.Thing{Name: exec, Type: fmt.Sprintf("executable in %s", ws)}
entityView := views.NewEntityView(render, entity, types.EntityFormatDocument)
keys := []types.KeyCallback{
{Key: "r", Label: "run", Callback: func() error {
container.SetNotice(
fmt.Sprintf("Running: %s/%s", ws, exec),
themes.OutputLevelInfo,
)
return nil
}},
{Key: "e", Label: "edit", Callback: func() error {
container.SetNotice("Opening in editor...", themes.OutputLevelInfo)
return nil
}},
}
return entityView, keys
},
}
}
func buildFormView(container *tuikit.Container) tuikit.View {
f, err := views.NewFormView(
container.RenderState(),
&views.FormField{
Key: "author",
Title: "Favorite Author",
Required: true,
},
&views.FormField{
Key: "color",
Title: "Favorite Color",
Default: "pink",
Required: false,
Description: "hint: it's pink",
},
&views.FormField{
Key: "confirm",
Title: "Ready to submit?",
Type: views.PromptTypeConfirm,
},
)
if err != nil {
panic(err)
}
f.Callback = func(v map[string]any) error {
inner := &sampleTypes.Echo{
Content: fmt.Sprintf(
"Thank you for tell me that your favorite author "+
"is %s and your favorite color is %s!",
f.FindByKey("author").Value(),
f.FindByKey("color").Value(),
),
}
container.SetNextView(views.NewFrameView(inner))
return nil
}
return f
}