From 07a0ffde0aeadd941a8bc48946750ad8b9393c15 Mon Sep 17 00:00:00 2001 From: Toby Padilla Date: Sun, 8 Aug 2021 16:04:16 -0500 Subject: [PATCH] Load README on repo menu entry active --- tui/bubble.go | 3 +++ tui/bubbles/selection/bubble.go | 21 +++++++++++++++++++-- tui/bubbles/selection/style.go | 4 ++-- tui/commands.go | 5 +++-- tui/defaults.go | 3 +-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/tui/bubble.go b/tui/bubble.go index 8c8c810c7feb613ca33cfa5640aaa14897041edf..8d1080a35acdba204757bb215d32716665e3b8d1 100644 --- a/tui/bubble.go +++ b/tui/bubble.go @@ -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 { diff --git a/tui/bubbles/selection/bubble.go b/tui/bubbles/selection/bubble.go index ab4f0c6bdff16af252f5d958632348a0af6970ba..f148acb1ef77127867bc86a5f5cfb2ea3c6af8ff 100644 --- a/tui/bubbles/selection/bubble.go +++ b/tui/bubbles/selection/bubble.go @@ -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 @@ -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], diff --git a/tui/bubbles/selection/style.go b/tui/bubbles/selection/style.go index 8aeeb002b267f9eb4c99208be42b95c92bac6ebc..120fc75a70134528e5f05b04b9c339d641b1115b 100644 --- a/tui/bubbles/selection/style.go +++ b/tui/bubbles/selection/style.go @@ -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")) diff --git a/tui/commands.go b/tui/commands.go index a32ad7d4c89d7fd75c307d80d8014e8df7224e92..0018e2b49b102348ff9fe287fc44cf4ab4d894cf 100644 --- a/tui/commands.go +++ b/tui/commands.go @@ -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 { @@ -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 } } diff --git a/tui/defaults.go b/tui/defaults.go index 6724b8101a430fe080e08ff2795ac2b6c0bac983..b69c4bb99d1b96835abed8a20c7c017ea6ccf767 100644 --- a/tui/defaults.go +++ b/tui/defaults.go @@ -17,8 +17,7 @@ const defaultConfig = `{ "menu": [ { "name": "Home", - "repo": "config", - "note": "" + "repo": "config" } ] }`