gitstack

grindlemire/go-tui code browser

1.8 KB Go 97 lines 2026-06-03 · 25447c4 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
// Code generated by tui generate. DO NOT EDIT.
// Source: alias.gsx

package testdata

import (
	"fmt"

	"github.com/grindlemire/go-tui"
	gui "github.com/grindlemire/go-tui"
)

type aliasHelper struct{}

func (foo aliasHelper) State() string {
	return "not tui state"
}

type AliasView struct {
	Root      *tui.Element
	watchers  []tui.Watcher
	bindApp   func(*tui.App)
	unbindApp func()
}

func (v *AliasView) UnbindApp() {
	if v.unbindApp != nil {
		v.unbindApp()
	}
}

func (v *AliasView) GetRoot() *tui.Element { return v.Root }

func (v *AliasView) GetWatchers() []tui.Watcher { return v.watchers }

func (v *AliasView) Render(app *tui.App) *tui.Element { return v.Root }

func (v *AliasView) BindApp(app *tui.App) {
	if v.bindApp != nil {
		v.bindApp(app)
	}
}

func (v *AliasView) UpdateProps(fresh tui.Component) {
	f, ok := fresh.(*AliasView)
	if !ok {
		return
	}
	v.Root = f.Root
	v.watchers = f.watchers
	v.bindApp = f.bindApp
	v.unbindApp = f.unbindApp
}

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

var _ tui.AppUnbinder = (*AliasView)(nil)

var _ tui.PropsUpdater = (*AliasView)(nil)

func Alias(counter *gui.State[int]) *AliasView {
	var view AliasView
	var watchers []tui.Watcher

	label := gui.NewState("alias state")
	foo := aliasHelper{}
	__tui_0 := tui.New(
		tui.WithBorder(gui.BorderSingle),
		tui.WithPadding(1),
	)
	__tui_1 := tui.New(
		tui.WithText(label.Get()),
	)
	__tui_0.AddChild(__tui_1)
	__tui_2 := tui.New(
		tui.WithText(fmt.Sprintf("%d", counter.Get())),
	)
	__tui_0.AddChild(__tui_2)
	__tui_3 := tui.New(
		tui.WithText(foo.State()),
	)
	__tui_0.AddChild(__tui_3)

	__bindApp := func(app *tui.App) {
	}

	__unbindApp := func() {
	}

	view = AliasView{
		Root:      __tui_0,
		watchers:  watchers,
		bindApp:   __bindApp,
		unbindApp: __unbindApp,
	}
	return &view
}