commands.go

 1package tui
 2
 3import (
 4	"smoothie/tui/bubbles/commits"
 5	"smoothie/tui/bubbles/selection"
 6
 7	tea "github.com/charmbracelet/bubbletea"
 8)
 9
10type windowMsg struct{}
11type errMsg struct{ err error }
12
13func (e errMsg) Error() string {
14	return e.err.Error()
15}
16
17func (b *Bubble) windowChangesCmd() tea.Msg {
18	w := <-b.windowChanges
19	b.width = w.Width
20	b.height = w.Height
21	return windowMsg{}
22}
23
24func (b *Bubble) loadGitCmd() tea.Msg {
25	b.repos = b.repoSource.AllRepos()
26	rs := make([]string, 0)
27	for _, r := range b.repos {
28		rs = append(rs, r.Name)
29	}
30	b.repoSelect = selection.NewBubble(rs)
31	b.boxes[0] = b.repoSelect
32	b.commitsLog = commits.NewBubble(
33		b.height-verticalPadding-2,
34		boxRightWidth-horizontalPadding-2,
35		b.repoSource.GetCommits(200),
36	)
37	b.boxes[1] = b.commitsLog
38	b.activeBox = 0
39	b.state = loadedState
40	return nil
41}