Skip to content

Commit 2adc003

Browse files
committed
bubbletea: adds code comments
1 parent c10dccd commit 2adc003

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

bubbletea/bubbletea.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,33 @@ import (
77
tea "github.com/charmbracelet/bubbletea"
88
)
99

10+
// BubbleTea represents the CLI component that wraps the `bubbletea` library.
1011
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.
1319
choices []string
14-
ui UI
20+
21+
// ui is the UI of the CLI.
22+
ui UI
1523
}
1624

25+
// UI represents the UI struct for the `BubbleTea` component.
1726
type UI struct {
27+
// header is the UI header text.
1828
header string
1929
}
2030

31+
// Init is the `BubbleTea` method required for implementing the `Model` interface.
2132
func (b BubbleTea) Init() tea.Cmd {
2233
return nil
2334
}
2435

36+
// Update is the `BubbleTea` method required for implementing the `Model` interface.
2537
func (b BubbleTea) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:golint,ireturn
2638
keyMsg, ok := msg.(tea.KeyMsg)
2739
if !ok {
@@ -55,6 +67,7 @@ func (b BubbleTea) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:golint,ir
5567
return b, nil
5668
}
5769

70+
// View is the `BubbleTea` method required for implementing the `Model` interface.
5871
func (b BubbleTea) View() string {
5972
s := strings.Builder{}
6073
s.WriteString(b.ui.header)
@@ -79,19 +92,23 @@ func (b BubbleTea) View() string {
7992
return s.String()
8093
}
8194

95+
// RunResult represents the result of the run method.
8296
type RunResult struct {
8397
Choice string
8498
}
8599

100+
// Params represents the parameters struct for the new method.
86101
type Params struct {
87102
Choices []string
88103
UI UIParams
89104
}
90105

106+
// UIParams represents the UI parameters for the new method parameters.
91107
type UIParams struct {
92108
Header string
93109
}
94110

111+
// New returns a pointer for the `BubbleTea` component.
95112
func New(p *Params) *BubbleTea {
96113
return &BubbleTea{
97114
choices: p.Choices,
@@ -101,6 +118,7 @@ func New(p *Params) *BubbleTea {
101118
}
102119
}
103120

121+
// Run runs the `BubbleTea` component and returns its result.
104122
func (b BubbleTea) Run() (*RunResult, error) {
105123
teaProgram := tea.NewProgram(b)
106124

0 commit comments

Comments
 (0)