gitstack

grindlemire/go-tui code browser

3.1 KB Go 126 lines 2026-04-18 · dcf2824 raw
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
// Code generated by tui generate. DO NOT EDIT.
// Source: app.gsx

package main

import (
	tui "github.com/grindlemire/go-tui"
)

type myApp struct {
	searchActive *tui.State[bool]
	query        *tui.State[string]
	category     *tui.State[string]
}

func MyApp() *myApp {
	return &myApp{
		searchActive: tui.NewState(false),
		query:        tui.NewState(""),
		category:     tui.NewState("Documents"),
	}
}

func (a *myApp) KeyMap() tui.KeyMap {
	km := tui.KeyMap{
		tui.On(tui.Rune('c').Ctrl(), func(ke tui.KeyEvent) { ke.App().Stop() }),
	}
	if !a.searchActive.Get() {
		km = append(km, tui.On(tui.Rune('/'), func(ke tui.KeyEvent) {
			a.searchActive.Set(true)
		}))
		km = append(km, tui.On(tui.Rune('q'), func(ke tui.KeyEvent) {
			ke.App().Stop()
		}))
	}
	return km
}

func (a *myApp) Render(app *tui.App) *tui.Element {
	__tui_0 := tui.New(
		tui.WithDisplay(tui.DisplayFlex), tui.WithDirection(tui.Column),
		tui.WithHeightPercent(100.00),
		tui.WithBorder(tui.BorderRounded),
		tui.WithBorderStyle(tui.NewStyle().Foreground(tui.Cyan)),
	)
	__tui_1 := tui.New(
		tui.WithDisplay(tui.DisplayFlex), tui.WithDirection(tui.Row),
		tui.WithJustify(tui.JustifyCenter),
		tui.WithFlexShrink(0),
		tui.WithPaddingTRBL(0, 1, 0, 1),
	)
	__tui_2 := tui.New(
		tui.WithText("File Explorer"),
		tui.WithTextGradient(tui.NewGradient(tui.Cyan, tui.Magenta).WithDirection(tui.GradientHorizontal)),
		tui.WithTextStyle(tui.NewStyle().Bold()),
	)
	__tui_1.AddChild(__tui_2)
	__tui_0.AddChild(__tui_1)
	__tui_3 := tui.New(
		tui.WithHR(),
	)
	__tui_0.AddChild(__tui_3)
	__tui_4 := tui.New(
		tui.WithDisplay(tui.DisplayFlex), tui.WithDirection(tui.Row),
		tui.WithFlexGrow(1),
		tui.WithMinHeight(0),
		tui.WithOverflow(tui.OverflowHidden),
	)
	__tui_5 := app.Mount(a, 0, func() tui.Component {
		return Sidebar(a.category)
	})
	__tui_4.AddChild(__tui_5)
	__tui_6 := app.Mount(a, 1, func() tui.Component {
		return Content(a.category, a.query)
	})
	__tui_4.AddChild(__tui_6)
	__tui_0.AddChild(__tui_4)
	__tui_7 := app.Mount(a, 2, func() tui.Component {
		return SearchBar(a.searchActive, a.query)
	})
	__tui_0.AddChild(__tui_7)
	__tui_8 := tui.New(
		tui.WithHR(),
	)
	__tui_0.AddChild(__tui_8)
	__tui_9 := tui.New(
		tui.WithDisplay(tui.DisplayFlex), tui.WithDirection(tui.Row),
		tui.WithJustify(tui.JustifyCenter),
		tui.WithFlexShrink(0),
		tui.WithPaddingTRBL(0, 1, 0, 1),
	)
	__tui_10 := tui.New(
		tui.WithText("/search | Ctrl+B sidebar | j/k navigate | q quit"),
		tui.WithTextStyle(tui.NewStyle().Dim()),
	)
	__tui_9.AddChild(__tui_10)
	__tui_0.AddChild(__tui_9)

	return __tui_0
}

// bindAppFields is generated. It wires the component's *tui.App,
// State, Events, and TextArea fields to app. When you override BindApp,
// call this helper instead of hand-maintaining the delegation list.
func (a *myApp) bindAppFields(app *tui.App) {
	if a.searchActive != nil {
		a.searchActive.BindApp(app)
	}
	if a.query != nil {
		a.query.BindApp(app)
	}
	if a.category != nil {
		a.category.BindApp(app)
	}
}

func (a *myApp) BindApp(app *tui.App) {
	a.bindAppFields(app)
}

var _ tui.AppBinder = (*myApp)(nil)

// Compile-time interface satisfaction checks.
var (
	_ tui.KeyListener = (*myApp)(nil)
)