07a0ffde0aeadd941a8bc48946750ad8b9393c15

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

Message

Load README on repo menu entry active

Diff

  1diff --git a/tui/bubble.go b/tui/bubble.go
  2index 8c8c810c7feb613ca33cfa5640aaa14897041edf..8d1080a35acdba204757bb215d32716665e3b8d1 100644
  3--- a/tui/bubble.go
  4+++ b/tui/bubble.go
  5@@ -105,6 +105,9 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
  6 		b.width = msg.Width
  7 		b.height = msg.Height
  8 	case selection.SelectedMsg:
  9+		b.activeBox = 1
 10+		cmds = append(cmds, b.getRepoCmd(b.repoMenu[msg.Index].Repo))
 11+	case selection.ActiveMsg:
 12 		cmds = append(cmds, b.getRepoCmd(b.repoMenu[msg.Index].Repo))
 13 	}
 14 	if b.state == loadedState {
 15diff --git a/tui/bubbles/selection/bubble.go b/tui/bubbles/selection/bubble.go
 16index ab4f0c6bdff16af252f5d958632348a0af6970ba..f148acb1ef77127867bc86a5f5cfb2ea3c6af8ff 100644
 17--- a/tui/bubbles/selection/bubble.go
 18+++ b/tui/bubbles/selection/bubble.go
 19@@ -10,6 +10,11 @@ type SelectedMsg struct {
 20 	Index int
 21 }
 22 
 23+type ActiveMsg struct {
 24+	Name  string
 25+	Index int
 26+}
 27+
 28 type Bubble struct {
 29 	NormalStyle   lipgloss.Style
 30 	SelectedStyle lipgloss.Style
 31@@ -49,19 +54,31 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 32 		case "k", "up":
 33 			if b.selectedItem > 0 {
 34 				b.selectedItem--
 35+				cmds = append(cmds, b.sendActiveMessage)
 36 			}
 37 		case "j", "down":
 38 			if b.selectedItem < len(b.Items)-1 {
 39 				b.selectedItem++
 40+				cmds = append(cmds, b.sendActiveMessage)
 41 			}
 42 		case "enter":
 43-			cmds = append(cmds, b.sendMessage)
 44+			cmds = append(cmds, b.sendSelectedMessage)
 45 		}
 46 	}
 47 	return b, tea.Batch(cmds...)
 48 }
 49 
 50-func (b *Bubble) sendMessage() tea.Msg {
 51+func (b *Bubble) sendActiveMessage() tea.Msg {
 52+	if b.selectedItem >= 0 && b.selectedItem < len(b.Items) {
 53+		return ActiveMsg{
 54+			Name:  b.Items[b.selectedItem],
 55+			Index: b.selectedItem,
 56+		}
 57+	}
 58+	return nil
 59+}
 60+
 61+func (b *Bubble) sendSelectedMessage() tea.Msg {
 62 	if b.selectedItem >= 0 && b.selectedItem < len(b.Items) {
 63 		return SelectedMsg{
 64 			Name:  b.Items[b.selectedItem],
 65diff --git a/tui/bubbles/selection/style.go b/tui/bubbles/selection/style.go
 66index 8aeeb002b267f9eb4c99208be42b95c92bac6ebc..120fc75a70134528e5f05b04b9c339d641b1115b 100644
 67--- a/tui/bubbles/selection/style.go
 68+++ b/tui/bubbles/selection/style.go
 69@@ -5,7 +5,7 @@ import (
 70 )
 71 
 72 var normalStyle = lipgloss.NewStyle().
 73-	Foreground(lipgloss.Color("#FFFFFF"))
 74+	Foreground(lipgloss.Color("#707070"))
 75 
 76 var selectedStyle = lipgloss.NewStyle().
 77-	Foreground(lipgloss.Color("#714C7B"))
 78+	Foreground(lipgloss.Color("#FFFFFF"))
 79diff --git a/tui/commands.go b/tui/commands.go
 80index a32ad7d4c89d7fd75c307d80d8014e8df7224e92..0018e2b49b102348ff9fe287fc44cf4ab4d894cf 100644
 81--- a/tui/commands.go
 82+++ b/tui/commands.go
 83@@ -50,8 +50,10 @@ func (b *Bubble) loadGitCmd() tea.Msg {
 84 		boxRightWidth-horizontalPadding-2,
 85 		b.repoSource.GetCommits(200),
 86 	)
 87+	msg := b.getRepoCmd("config")()
 88+	b.activeBox = 0
 89 	b.state = loadedState
 90-	return b.getRepoCmd("config")()
 91+	return msg
 92 }
 93 
 94 func (b *Bubble) getRepoCmd(name string) tea.Cmd {
 95@@ -65,7 +67,6 @@ func (b *Bubble) getRepoCmd(name string) tea.Cmd {
 96 		b.readmeViewport.Viewport.Width = boxLeftWidth - 2
 97 		b.readmeViewport.Viewport.SetContent(r.Readme)
 98 		b.boxes[1] = b.readmeViewport
 99-		b.activeBox = 1
100 		return nil
101 	}
102 }
103diff --git a/tui/defaults.go b/tui/defaults.go
104index 6724b8101a430fe080e08ff2795ac2b6c0bac983..b69c4bb99d1b96835abed8a20c7c017ea6ccf767 100644
105--- a/tui/defaults.go
106+++ b/tui/defaults.go
107@@ -17,8 +17,7 @@ const defaultConfig = `{
108 	"menu": [
109 	  {
110 			"name": "Home",
111-			"repo": "config",
112-			"note": ""
113+			"repo": "config"
114 		}
115 	]
116 }`