5efc4b87504c8ae1033226643467a430854bf409
- Author
- Toby Padilla <toby@charm.sh>
- Committer
- Toby Padilla <toby@charm.sh>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/git/git.go b/git/git.go
2index 7293c0694eafd737714283b44d9f29c369f3bd6b..eca024be3acaf0e84b9d5dc86c6c2f53a911e056 100644
3--- a/git/git.go
4+++ b/git/git.go
5@@ -88,6 +88,13 @@ func (rs *RepoSource) loadRepos() {
6 l.ForEach(func(c *object.Commit) error {
7 if r.LastUpdated == nil {
8 r.LastUpdated = &c.Author.When
9+ rf, err := c.File("README.md")
10+ if err == nil {
11+ rmd, err := rf.Contents()
12+ if err == nil {
13+ r.Readme = rmd
14+ }
15+ }
16 }
17 rs.commits = append(rs.commits, RepoCommit{Name: rn, Commit: c})
18 return nil
19diff --git a/tui/bubble.go b/tui/bubble.go
20index abdc6ef9910b3a832e3fdabb2536c746da58c1bd..a5e8cfbd74e56422894c857f807ee22abe9cec00 100644
21--- a/tui/bubble.go
22+++ b/tui/bubble.go
23@@ -3,8 +3,11 @@ package tui
24 import (
25 "fmt"
26 "smoothie/git"
27+ "smoothie/tui/bubbles/commits"
28+ "smoothie/tui/bubbles/selection"
29 "time"
30
31+ "github.com/charmbracelet/bubbles/viewport"
32 tea "github.com/charmbracelet/bubbletea"
33 "github.com/charmbracelet/lipgloss"
34 "github.com/gliderlabs/ssh"
35@@ -23,14 +26,17 @@ const (
36 type Model struct {
37 state sessionState
38 error string
39- info string
40 width int
41 height int
42 windowChanges <-chan ssh.Window
43 repoSource *git.RepoSource
44 repos []*git.Repo
45- activeBubble int
46- bubbles []tea.Model
47+ boxes []tea.Model
48+ activeBox int
49+
50+ repoSelect *selection.Bubble
51+ commitsLog *commits.Bubble
52+ readmeViewport *ViewportBubble
53 }
54
55 func NewModel(width int, height int, windowChanges <-chan ssh.Window, repoSource *git.RepoSource) *Model {
56@@ -39,7 +45,13 @@ func NewModel(width int, height int, windowChanges <-chan ssh.Window, repoSource
57 height: height,
58 windowChanges: windowChanges,
59 repoSource: repoSource,
60- bubbles: make([]tea.Model, 2),
61+ boxes: make([]tea.Model, 2),
62+ readmeViewport: &ViewportBubble{
63+ Viewport: &viewport.Model{
64+ Width: boxRightWidth - horizontalPadding - 2,
65+ Height: height - verticalPadding - viewportHeightConstant,
66+ },
67+ },
68 }
69 m.state = startState
70 return m
71@@ -53,30 +65,33 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
72 cmds := make([]tea.Cmd, 0)
73 // Always allow state, error, info, window resize and quit messages
74 switch msg := msg.(type) {
75- case stateMsg:
76- m.state = msg.state
77 case tea.KeyMsg:
78 switch msg.String() {
79 case "q", "ctrl+c":
80 return m, tea.Quit
81 case "tab":
82- m.activeBubble = (m.activeBubble + 1) % 2
83+ m.activeBox = (m.activeBox + 1) % 2
84 }
85 case errMsg:
86 m.error = msg.Error()
87 m.state = errorState
88 return m, nil
89- case infoMsg:
90- m.info = msg.text
91 case windowMsg:
92 cmds = append(cmds, m.windowChangesCmd)
93 case tea.WindowSizeMsg:
94 m.width = msg.Width
95 m.height = msg.Height
96+ case selection.SelectedMsg:
97+ rmd := m.repos[msg.Index].Readme
98+ m.readmeViewport.Viewport.GotoTop()
99+ m.readmeViewport.Viewport.Height = m.height - verticalPadding - viewportHeightConstant
100+ m.readmeViewport.Viewport.Width = boxLeftWidth - 2
101+ m.readmeViewport.Viewport.SetContent(rmd)
102+ m.boxes[1] = m.readmeViewport
103 }
104 if m.state == loadedState {
105- b, cmd := m.bubbles[m.activeBubble].Update(msg)
106- m.bubbles[m.activeBubble] = b
107+ b, cmd := m.boxes[m.activeBox].Update(msg)
108+ m.boxes[m.activeBox] = b
109 if cmd != nil {
110 cmds = append(cmds, cmd)
111 }
112@@ -84,33 +99,32 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
113 return m, tea.Batch(cmds...)
114 }
115
116-func (m *Model) viewForBubble(i int, width int) string {
117+func (m *Model) viewForBox(i int, width int) string {
118 var ls lipgloss.Style
119- if i == m.activeBubble {
120+ if i == m.activeBox {
121 ls = activeBoxStyle.Width(width)
122 } else {
123diff --git a/tui/bubbles/commits/bubble.go b/tui/bubbles/commits/bubble.go
124index 1e7ed7ca596d50f1b686172d6422c1e67f64bedc..1894a504dc3cdaa6d5a3103385b70a40c1908659 100644
125--- a/tui/bubbles/commits/bubble.go
126+++ b/tui/bubbles/commits/bubble.go
127@@ -11,16 +11,15 @@ import (
128
129 type Bubble struct {
130 Commits []git.RepoCommit
131- Margin int
132- Width int
133 Height int
134+ Width int
135 viewport viewport.Model
136 }
137
138-func NewBubble(height int, margin int, width int, rcs []git.RepoCommit) *Bubble {
139+func NewBubble(height int, width int, rcs []git.RepoCommit) *Bubble {
140 b := &Bubble{
141 Commits: rcs,
142- viewport: viewport.Model{Height: height - margin, Width: width},
143+ viewport: viewport.Model{Height: height, Width: width},
144 }
145 s := ""
146 for _, rc := range rcs {
147@@ -37,8 +36,6 @@ func (b *Bubble) Init() tea.Cmd {
148 func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
149 cmds := make([]tea.Cmd, 0)
150 switch msg := msg.(type) {
151- case tea.WindowSizeMsg:
152- b.viewport.Height = msg.Height - b.Margin
153 case tea.KeyMsg:
154 switch msg.String() {
155 case "up", "k":
156diff --git a/tui/commands.go b/tui/commands.go
157index 3317d36520e72424c303aeb13c385fca80e3766e..4878ec99d38b3ca6cf75b4fdb8da5a61a3ddc615 100644
158--- a/tui/commands.go
159+++ b/tui/commands.go
160@@ -7,8 +7,6 @@ import (
161 tea "github.com/charmbracelet/bubbletea"
162 )
163
164-type stateMsg struct{ state sessionState }
165-type infoMsg struct{ text string }
166 type windowMsg struct{}
167 type errMsg struct{ err error }
168
169@@ -24,13 +22,20 @@ func (m *Model) windowChangesCmd() tea.Msg {
170 }
171
172 func (m *Model) loadGitCmd() tea.Msg {
173+ m.repos = m.repoSource.AllRepos()
174 rs := make([]string, 0)
175- for _, r := range m.repoSource.AllRepos() {
176+ for _, r := range m.repos {
177 rs = append(rs, r.Name)
178 }
179- m.bubbles[0] = selection.NewBubble(rs)
180- m.bubbles[1] = commits.NewBubble(m.height, 7, 80, m.repoSource.GetCommits(200))
181- m.activeBubble = 0
182+ m.repoSelect = selection.NewBubble(rs)
183+ m.boxes[0] = m.repoSelect
184+ m.commitsLog = commits.NewBubble(
185+ m.height-verticalPadding-2,
186+ boxRightWidth-horizontalPadding-2,
187+ m.repoSource.GetCommits(200),
188+ )
189+ m.boxes[1] = m.commitsLog
190+ m.activeBox = 0
191 m.state = loadedState
192 return nil
193 }
194diff --git a/tui/style.go b/tui/style.go
195index 2cd8e6c0cf17853ecf082fbdfc63b7fc39005dae..1d04dc48eed9b329d4122d1a254fb7a975a37b1a 100644
196--- a/tui/style.go
197+++ b/tui/style.go
198@@ -4,22 +4,31 @@ import (
199 "github.com/charmbracelet/lipgloss"
200 )
201
202+const boxLeftWidth = 25
203+const boxRightWidth = 80
204+const headerHeight = 1
205+const footerHeight = 2
206+const appPadding = 1
207+const boxPadding = 1
208+const viewportHeightConstant = 7 // TODO figure out why this needs to be 7
209+const horizontalPadding = appPadding * 2
210+const verticalPadding = headerHeight + footerHeight + (appPadding * 2)
211+
212 var appBoxStyle = lipgloss.NewStyle().
213- PaddingLeft(2).
214- PaddingRight(2).
215- MarginBottom(1)
216+ PaddingLeft(appPadding).
217+ PaddingRight(appPadding)
218
219 var inactiveBoxStyle = lipgloss.NewStyle().
220 Foreground(lipgloss.Color("#606060")).
221 BorderStyle(lipgloss.RoundedBorder()).
222 BorderForeground(lipgloss.Color("#303030")).
223- Padding(1)
224+ Padding(boxPadding)
225
226 var activeBoxStyle = lipgloss.NewStyle().
227 Foreground(lipgloss.Color("#FFFFFF")).
228 BorderStyle(lipgloss.RoundedBorder()).
229 BorderForeground(lipgloss.Color("#714C7B")).
230- Padding(1)
231+ Padding(boxPadding)
232
233 var headerStyle = lipgloss.NewStyle().
234 Foreground(lipgloss.Color("#670083")).
235diff --git a/tui/viewport_patch.go b/tui/viewport_patch.go
236new file mode 100644
237index 0000000000000000000000000000000000000000..b924145a069d6c7765a15540d7c06b55e990084e
238--- /dev/null
239+++ b/tui/viewport_patch.go
240@@ -0,0 +1,24 @@
241+package tui
242+
243+import (
244+ "github.com/charmbracelet/bubbles/viewport"
245+ tea "github.com/charmbracelet/bubbletea"
246+)
247+
248+type ViewportBubble struct {
249+ Viewport *viewport.Model
250+}
251+
252+func (v *ViewportBubble) Init() tea.Cmd {
253+ return nil
254+}
255+
256+func (v *ViewportBubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
257+ vp, cmd := v.Viewport.Update(msg)
258+ v.Viewport = &vp
259+ return v, cmd
260+}
261+
262+func (v *ViewportBubble) View() string {
263+ return v.Viewport.View()
264+}