Skip to content

Commit

Permalink
Load README on repo menu entry active
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Padilla committed Aug 8, 2021
1 parent 1e58693 commit 07a0ffd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions tui/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
b.width = msg.Width
b.height = msg.Height
case selection.SelectedMsg:
b.activeBox = 1
cmds = append(cmds, b.getRepoCmd(b.repoMenu[msg.Index].Repo))
case selection.ActiveMsg:
cmds = append(cmds, b.getRepoCmd(b.repoMenu[msg.Index].Repo))
}
if b.state == loadedState {
Expand Down
21 changes: 19 additions & 2 deletions tui/bubbles/selection/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ type SelectedMsg struct {
Index int
}

type ActiveMsg struct {
Name string
Index int
}

type Bubble struct {
NormalStyle lipgloss.Style
SelectedStyle lipgloss.Style
Expand Down Expand Up @@ -49,19 +54,31 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "k", "up":
if b.selectedItem > 0 {
b.selectedItem--
cmds = append(cmds, b.sendActiveMessage)
}
case "j", "down":
if b.selectedItem < len(b.Items)-1 {
b.selectedItem++
cmds = append(cmds, b.sendActiveMessage)
}
case "enter":
cmds = append(cmds, b.sendMessage)
cmds = append(cmds, b.sendSelectedMessage)
}
}
return b, tea.Batch(cmds...)
}

func (b *Bubble) sendMessage() tea.Msg {
func (b *Bubble) sendActiveMessage() tea.Msg {
if b.selectedItem >= 0 && b.selectedItem < len(b.Items) {
return ActiveMsg{
Name: b.Items[b.selectedItem],
Index: b.selectedItem,
}
}
return nil
}

func (b *Bubble) sendSelectedMessage() tea.Msg {
if b.selectedItem >= 0 && b.selectedItem < len(b.Items) {
return SelectedMsg{
Name: b.Items[b.selectedItem],
Expand Down
4 changes: 2 additions & 2 deletions tui/bubbles/selection/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

var normalStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#FFFFFF"))
Foreground(lipgloss.Color("#707070"))

var selectedStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#714C7B"))
Foreground(lipgloss.Color("#FFFFFF"))
5 changes: 3 additions & 2 deletions tui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func (b *Bubble) loadGitCmd() tea.Msg {
boxRightWidth-horizontalPadding-2,
b.repoSource.GetCommits(200),
)
msg := b.getRepoCmd("config")()
b.activeBox = 0
b.state = loadedState
return b.getRepoCmd("config")()
return msg
}

func (b *Bubble) getRepoCmd(name string) tea.Cmd {
Expand All @@ -65,7 +67,6 @@ func (b *Bubble) getRepoCmd(name string) tea.Cmd {
b.readmeViewport.Viewport.Width = boxLeftWidth - 2
b.readmeViewport.Viewport.SetContent(r.Readme)
b.boxes[1] = b.readmeViewport
b.activeBox = 1
return nil
}
}
3 changes: 1 addition & 2 deletions tui/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const defaultConfig = `{
"menu": [
{
"name": "Home",
"repo": "config",
"note": ""
"repo": "config"
}
]
}`
Expand Down

0 comments on commit 07a0ffd

Please sign in to comment.