@@ -7,21 +7,33 @@ import (
7
7
tea "github.com/charmbracelet/bubbletea"
8
8
)
9
9
10
+ // BubbleTea represents the CLI component that wraps the `bubbletea` library.
10
11
type BubbleTea struct {
11
- cursor int
12
- choice string
12
+ // cursor is the reference of the current CLI choice.
13
+ cursor int
14
+
15
+ // choice is the current CLI choice.
16
+ choice string
17
+
18
+ // choices is the slice of CLI choices.
13
19
choices []string
14
- ui UI
20
+
21
+ // ui is the UI of the CLI.
22
+ ui UI
15
23
}
16
24
25
+ // UI represents the UI struct for the `BubbleTea` component.
17
26
type UI struct {
27
+ // header is the UI header text.
18
28
header string
19
29
}
20
30
31
+ // Init is the `BubbleTea` method required for implementing the `Model` interface.
21
32
func (b BubbleTea ) Init () tea.Cmd {
22
33
return nil
23
34
}
24
35
36
+ // Update is the `BubbleTea` method required for implementing the `Model` interface.
25
37
func (b BubbleTea ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) { //nolint:golint,ireturn
26
38
keyMsg , ok := msg .(tea.KeyMsg )
27
39
if ! ok {
@@ -55,6 +67,7 @@ func (b BubbleTea) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:golint,ir
55
67
return b , nil
56
68
}
57
69
70
+ // View is the `BubbleTea` method required for implementing the `Model` interface.
58
71
func (b BubbleTea ) View () string {
59
72
s := strings.Builder {}
60
73
s .WriteString (b .ui .header )
@@ -79,19 +92,23 @@ func (b BubbleTea) View() string {
79
92
return s .String ()
80
93
}
81
94
95
+ // RunResult represents the result of the run method.
82
96
type RunResult struct {
83
97
Choice string
84
98
}
85
99
100
+ // Params represents the parameters struct for the new method.
86
101
type Params struct {
87
102
Choices []string
88
103
UI UIParams
89
104
}
90
105
106
+ // UIParams represents the UI parameters for the new method parameters.
91
107
type UIParams struct {
92
108
Header string
93
109
}
94
110
111
+ // New returns a pointer for the `BubbleTea` component.
95
112
func New (p * Params ) * BubbleTea {
96
113
return & BubbleTea {
97
114
choices : p .Choices ,
@@ -101,6 +118,7 @@ func New(p *Params) *BubbleTea {
101
118
}
102
119
}
103
120
121
+ // Run runs the `BubbleTea` component and returns its result.
104
122
func (b BubbleTea ) Run () (* RunResult , error ) {
105
123
teaProgram := tea .NewProgram (b )
106
124
0 commit comments