e69529f964977d9f392803bb0275186fa9308223

Author
Toby Padilla <toby@charm.sh>
Committer
Toby Padilla <toby@charm.sh>
Date

Message

Rename Model to Bubble

Diff

This diff is truncated to protect this page.

  1diff --git a/tui/bubble.go b/tui/bubble.go
  2index 79ff7a82dc7aca9f4968692126297b6bff98dfa4..42fdef6b01732ffa202c81d70101a78b7d179b3a 100644
  3--- a/tui/bubble.go
  4+++ b/tui/bubble.go
  5@@ -25,7 +25,7 @@ const (
  6 	quitState
  7 )
  8 
  9-type Model struct {
 10+type Bubble struct {
 11 	state          sessionState
 12 	error          string
 13 	width          int
 14@@ -40,8 +40,8 @@ type Model struct {
 15 	readmeViewport *ViewportBubble
 16 }
 17 
 18-func NewModel(width int, height int, windowChanges <-chan ssh.Window, repoSource *git.RepoSource) *Model {
 19-	m := &Model{
 20+func NewBubble(width int, height int, windowChanges <-chan ssh.Window, repoSource *git.RepoSource) *Bubble {
 21+	b := &Bubble{
 22 		width:         width,
 23 		height:        height,
 24 		windowChanges: windowChanges,
 25@@ -54,76 +54,76 @@ func NewModel(width int, height int, windowChanges <-chan ssh.Window, repoSource
 26 			},
 27 		},
 28 	}
 29-	m.state = startState
 30-	return m
 31+	b.state = startState
 32+	return b
 33 }
 34 
 35-func (m *Model) Init() tea.Cmd {
 36-	return tea.Batch(m.windowChangesCmd, m.loadGitCmd)
 37+func (b *Bubble) Init() tea.Cmd {
 38+	return tea.Batch(b.windowChangesCmd, b.loadGitCmd)
 39 }
 40 
 41-func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 42+func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 43 	cmds := make([]tea.Cmd, 0)
 44 	// Always allow state, error, info, window resize and quit messages
 45 	switch msg := msg.(type) {
 46 	case tea.KeyMsg:
 47 		switch msg.String() {
 48 		case "q", "ctrl+c":
 49-			return m, tea.Quit
 50+			return b, tea.Quit
 51 		case "tab":
 52-			m.activeBox = (m.activeBox + 1) % 2
 53+			b.activeBox = (b.activeBox + 1) % 2
 54 		}
 55 	case errMsg:
 56-		m.error = msg.Error()
 57-		m.state = errorState
 58-		return m, nil
 59+		b.error = msg.Error()
 60+		b.state = errorState
 61+		return b, nil
 62 	case windowMsg:
 63-		cmds = append(cmds, m.windowChangesCmd)
 64+		cmds = append(cmds, b.windowChangesCmd)
 65 	case tea.WindowSizeMsg:
 66-		m.width = msg.Width
 67-		m.height = msg.Height
 68+		b.width = msg.Width
 69+		b.height = msg.Height
 70 	case selection.SelectedMsg:
 71-		rmd := m.repos[msg.Index].Readme
 72-		m.readmeViewport.Viewport.GotoTop()
 73-		m.readmeViewport.Viewport.Height = m.height - verticalPadding - viewportHeightConstant
 74-		m.readmeViewport.Viewport.Width = boxLeftWidth - 2
 75-		m.readmeViewport.Viewport.SetContent(rmd)
 76-		m.boxes[1] = m.readmeViewport
 77+		rmd := b.repos[msg.Index].Readme
 78+		b.readmeViewport.Viewport.GotoTop()
 79+		b.readmeViewport.Viewport.Height = b.height - verticalPadding - viewportHeightConstant
 80+		b.readmeViewport.Viewport.Width = boxLeftWidth - 2
 81+		b.readmeViewport.Viewport.SetContent(rmd)
 82+		b.boxes[1] = b.readmeViewport
 83 	}
 84-	if m.state == loadedState {
 85-		b, cmd := m.boxes[m.activeBox].Update(msg)
 86-		m.boxes[m.activeBox] = b
 87+	if b.state == loadedState {
 88+		ab, cmd := b.boxes[b.activeBox].Update(msg)
 89+		b.boxes[b.activeBox] = ab
 90 		if cmd != nil {
 91 			cmds = append(cmds, cmd)
 92 		}
 93 	}
 94-	return m, tea.Batch(cmds...)
 95+	return b, tea.Batch(cmds...)
 96 }
 97 
 98-func (m *Model) viewForBox(i int, width int) string {
 99+func (b *Bubble) viewForBox(i int, width int) string {
100 	var ls lipgloss.Style
101-	if i == m.activeBox {
102+	if i == b.activeBox {
103 		ls = activeBoxStyle.Width(width)
104 	} else {
105diff --git a/tui/commands.go b/tui/commands.go
106index 4878ec99d38b3ca6cf75b4fdb8da5a61a3ddc615..c7c62427a1376db76470d5717989f7b3bb3d4859 100644
107--- a/tui/commands.go
108+++ b/tui/commands.go
109@@ -14,28 +14,28 @@ func (e errMsg) Error() string {
110 	return e.err.Error()
111 }
112 
113-func (m *Model) windowChangesCmd() tea.Msg {
114-	w := <-m.windowChanges
115-	m.width = w.Width
116-	m.height = w.Height
117+func (b *Bubble) windowChangesCmd() tea.Msg {
118+	w := <-b.windowChanges
119+	b.width = w.Width
120+	b.height = w.Height
121 	return windowMsg{}
122 }
123 
124-func (m *Model) loadGitCmd() tea.Msg {
125-	m.repos = m.repoSource.AllRepos()
126+func (b *Bubble) loadGitCmd() tea.Msg {
127+	b.repos = b.repoSource.AllRepos()
128 	rs := make([]string, 0)
129-	for _, r := range m.repos {
130+	for _, r := range b.repos {
131 		rs = append(rs, r.Name)
132 	}
133-	m.repoSelect = selection.NewBubble(rs)
134-	m.boxes[0] = m.repoSelect
135-	m.commitsLog = commits.NewBubble(
136-		m.height-verticalPadding-2,
137+	b.repoSelect = selection.NewBubble(rs)
138+	b.boxes[0] = b.repoSelect
139+	b.commitsLog = commits.NewBubble(
140+		b.height-verticalPadding-2,
141 		boxRightWidth-horizontalPadding-2,
142-		m.repoSource.GetCommits(200),
143+		b.repoSource.GetCommits(200),
144 	)
145-	m.boxes[1] = m.commitsLog
146-	m.activeBox = 0
147-	m.state = loadedState
148+	b.boxes[1] = b.commitsLog
149+	b.activeBox = 0
150+	b.state = loadedState
151 	return nil
152 }