chore: adjust highlight style in top level repo selector

Christian Rocha created

Change summary

ui/components/selector/selector.go |  3 +
ui/pages/selection/item.go         | 51 +++++++++----------------------
ui/pages/selection/selection.go    |  2 
ui/styles/styles.go                | 51 ++++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+), 38 deletions(-)

Detailed changes

ui/components/selector/selector.go 🔗

@@ -15,7 +15,8 @@ type Selector struct {
 	filterState list.FilterState
 }
 
-// IdentifiableItem is an item that can be identified by a string. Implements list.DefaultItem.
+// IdentifiableItem is an item that can be identified by a string. Implements
+// list.DefaultItem.
 type IdentifiableItem interface {
 	list.DefaultItem
 	ID() string

ui/pages/selection/item.go 🔗

@@ -84,7 +84,6 @@ func (d ItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
 
 // Render implements list.ItemDelegate.
 func (d ItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
-	styles := d.common.Styles
 	i := listItem.(Item)
 	s := strings.Builder{}
 	var matchedRunes []int
@@ -95,20 +94,13 @@ func (d ItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
 		isFiltered = m.FilterState() == list.Filtering || m.FilterState() == list.FilterApplied
 	)
 
-	itemStyle := styles.MenuItem.Copy()
+	styles := d.common.Styles.RepoSelector.Normal
 	if isSelected {
-		itemStyle = itemStyle.Copy().
-			BorderStyle(lipgloss.Border{
-				Left: "┃",
-			}).
-			BorderForeground(styles.ActiveBorderColor)
-		if d.activePane != nil && *d.activePane == readmePane {
-			itemStyle = itemStyle.BorderForeground(styles.InactiveBorderColor)
-		}
+		styles = d.common.Styles.RepoSelector.Active
 	}
 
 	title := i.Title()
-	title = common.TruncateString(title, m.Width()-itemStyle.GetHorizontalFrameSize())
+	title = common.TruncateString(title, m.Width()-styles.Base.GetHorizontalFrameSize())
 	if i.repo.IsPrivate() {
 		title += " 🔒"
 	}
@@ -116,15 +108,12 @@ func (d ItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
 		title += " "
 	}
 	updatedStr := fmt.Sprintf(" Updated %s", humanize.Time(i.lastUpdate))
-	if m.Width()-itemStyle.GetHorizontalFrameSize()-lipgloss.Width(updatedStr)-lipgloss.Width(title) <= 0 {
+	if m.Width()-styles.Base.GetHorizontalFrameSize()-lipgloss.Width(updatedStr)-lipgloss.Width(title) <= 0 {
 		updatedStr = ""
 	}
-	updatedStyle := styles.MenuLastUpdate.Copy().
+	updatedStyle := styles.Updated.Copy().
 		Align(lipgloss.Right).
-		Width(m.Width() - itemStyle.GetHorizontalFrameSize() - lipgloss.Width(title))
-	if isSelected {
-		updatedStyle = updatedStyle.Bold(true)
-	}
+		Width(m.Width() - styles.Base.GetHorizontalFrameSize() - lipgloss.Width(title))
 	updated := updatedStyle.Render(updatedStr)
 
 	if isFiltered && index < len(m.VisibleItems()) {
@@ -141,30 +130,20 @@ func (d ItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
 		}
 		title = lipgloss.StyleRunes(title, matchedRunes, matched, unmatched)
 	}
-	titleStyle := lipgloss.NewStyle()
-	if isSelected {
-		titleStyle = titleStyle.Bold(true)
-	}
-	title = titleStyle.Render(title)
+	title = styles.Title.Render(title)
 	desc := i.Description()
-	descStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("243"))
-	if desc == "" {
-		desc = "No description"
-		descStyle = descStyle.Faint(true)
-	}
-	desc = common.TruncateString(desc, m.Width()-itemStyle.GetHorizontalFrameSize())
-	desc = descStyle.Render(desc)
+	desc = common.TruncateString(desc, m.Width()-styles.Base.GetHorizontalFrameSize())
+	desc = styles.Desc.Render(desc)
 
 	s.WriteString(lipgloss.JoinHorizontal(lipgloss.Bottom, title, updated))
-	s.WriteString("\n")
+	s.WriteRune('\n')
 	s.WriteString(desc)
-	s.WriteString("\n")
-	cmdStyle := styles.Repo.Command.Copy()
-	cmd := common.TruncateString(i.Command(), m.Width()-itemStyle.GetHorizontalFrameSize())
-	cmd = cmdStyle.Render(cmd)
+	s.WriteRune('\n')
+	cmd := common.TruncateString(i.Command(), m.Width()-styles.Base.GetHorizontalFrameSize())
+	cmd = styles.Command.Render(cmd)
 	if !i.copied.IsZero() && i.copied.Add(time.Second).After(time.Now()) {
-		cmd = cmdStyle.Render("Copied!")
+		cmd = styles.Command.Render("Copied!")
 	}
 	s.WriteString(cmd)
-	fmt.Fprint(w, itemStyle.Render(s.String()))
+	fmt.Fprint(w, styles.Base.Render(s.String()))
 }

ui/pages/selection/selection.go 🔗

@@ -52,7 +52,7 @@ func New(cfg *config.Config, pk ssh.PublicKey, common common.Common) *Selection
 	}
 	t := tabs.New(common, ts)
 	t.TabSeparator = lipgloss.NewStyle()
-	t.TabInactive = common.Styles.TopLevelTabNormal.Copy()
+	t.TabInactive = common.Styles.TopLevelNormalTab.Copy()
 	t.TabActive = common.Styles.TopLevelActiveTab.Copy()
 	t.TabDot = common.Styles.TopLevelActiveTabDot.Copy()
 	t.UseDot = true

ui/styles/styles.go 🔗

@@ -21,6 +21,23 @@ type Styles struct {
 	MenuItem       lipgloss.Style
 	MenuLastUpdate lipgloss.Style
 
+	RepoSelector struct {
+		Normal struct {
+			Base,
+			Title,
+			Desc,
+			Command,
+			Updated lipgloss.Style
+		}
+		Active struct {
+			Base,
+			Title,
+			Desc,
+			Command,
+			Updated lipgloss.Style
+		}
+	}
+
 	Repo struct {
 		Base       lipgloss.Style
 		Title      lipgloss.Style
@@ -154,6 +171,40 @@ func DefaultStyles() *Styles {
 	s.TopLevelActiveTabDot = lipgloss.NewStyle().
 		Foreground(lipgloss.Color("29"))
 
+	s.RepoSelector.Normal.Base = lipgloss.NewStyle().
+		PaddingLeft(1).
+		Border(lipgloss.Border{Left: " "}, false, false, false, true).
+		Height(3)
+
+	s.RepoSelector.Normal.Title = lipgloss.NewStyle().
+		Foreground(lipgloss.Color("212")).
+		Bold(true)
+
+	s.RepoSelector.Normal.Desc = lipgloss.NewStyle().
+		Foreground(lipgloss.Color("250"))
+
+	s.RepoSelector.Normal.Command = lipgloss.NewStyle().
+		Foreground(lipgloss.Color("246"))
+
+	s.RepoSelector.Normal.Updated = lipgloss.NewStyle()
+
+	s.RepoSelector.Active.Base = s.RepoSelector.Normal.Base.Copy().
+		BorderStyle(lipgloss.Border{Left: "┃"}).
+		BorderForeground(selectorColor)
+
+	s.RepoSelector.Active.Title = lipgloss.NewStyle().
+		Foreground(highlightColor).
+		Bold(true)
+
+	s.RepoSelector.Active.Desc = lipgloss.NewStyle().
+		Foreground(highlightColorDim)
+
+	s.RepoSelector.Active.Updated = s.RepoSelector.Normal.Updated.Copy().
+		Foreground(highlightColorDim)
+
+	s.RepoSelector.Active.Command = lipgloss.NewStyle().
+		Foreground(lipgloss.Color("138"))
+
 	s.MenuItem = lipgloss.NewStyle().
 		PaddingLeft(1).
 		Border(lipgloss.Border{