From 69a9d87dff1ca0d75fa14aa4588fc18c76d0ac79 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 10 Jun 2022 20:46:38 -0700 Subject: [PATCH] feat: apply highlight color to branchdes and tags --- ui/pages/repo/refsitem.go | 34 ++++++++++++++++++++++++---------- ui/styles/styles.go | 35 +++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/ui/pages/repo/refsitem.go b/ui/pages/repo/refsitem.go index d34f9d13a1189b29587eabd057145149577656fc..32010664baaa6548ebd3bd2b65ac61f0eaa9c486 100644 --- a/ui/pages/repo/refsitem.go +++ b/ui/pages/repo/refsitem.go @@ -7,6 +7,7 @@ import ( "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/soft-serve/git" "github.com/charmbracelet/soft-serve/ui/common" ) @@ -90,22 +91,35 @@ func (d RefItemDelegate) Render(w io.Writer, m list.Model, index int, listItem l return } + var st lipgloss.Style + var selector string + + isTag := i.Reference.IsTag() + isActive := index == m.Index() + + if isTag && isActive { + st = s.RefItemTagActive + } else if isTag { + st = s.RefItemTagInactive + } else if isActive { + st = s.RefItemActive + } else { + st = s.RefItemInactive + } + + if isActive { + selector = s.RefItemSelector.String() + } else { + selector = " " + } + ref := i.Short() ref = s.RefItemBranch.Render(ref) - if i.Reference.IsTag() { - ref = s.RefItemTag.Render(ref) - } refMaxWidth := m.Width() - s.RefItemSelector.GetMarginLeft() - s.RefItemSelector.GetWidth() - s.RefItemInactive.GetMarginLeft() ref = common.TruncateString(ref, refMaxWidth) - refStyle := s.RefItemInactive - selector := s.RefItemSelector.Render(" ") - if index == m.Index() { - selector = s.RefItemSelector.Render(">") - refStyle = s.RefItemActive - } - ref = refStyle.Render(ref) + ref = st.Render(ref) fmt.Fprint(w, selector, ref) } diff --git a/ui/styles/styles.go b/ui/styles/styles.go index 5e31984dd9bf1b3f3b65a6c095a3c4fd044b26f5..f5a2ea6b8fbd2b55c8651079f6ac1d7e5ff974a1 100644 --- a/ui/styles/styles.go +++ b/ui/styles/styles.go @@ -59,12 +59,13 @@ type Styles struct { LogCommitStatsDel lipgloss.Style LogPaginator lipgloss.Style - RefItemSelector lipgloss.Style - RefItemActive lipgloss.Style - RefItemInactive lipgloss.Style - RefItemBranch lipgloss.Style - RefItemTag lipgloss.Style - RefPaginator lipgloss.Style + RefItemSelector lipgloss.Style + RefItemActive lipgloss.Style + RefItemInactive lipgloss.Style + RefItemBranch lipgloss.Style + RefItemTagInactive lipgloss.Style + RefItemTagActive lipgloss.Style + RefPaginator lipgloss.Style TreeItemSelector lipgloss.Style TreeItemActive lipgloss.Style @@ -247,22 +248,28 @@ func DefaultStyles() *Styles { Margin(0). Align(lipgloss.Center) - s.RefItemInactive = lipgloss.NewStyle(). - MarginLeft(1) + s.RefItemInactive = lipgloss.NewStyle() s.RefItemSelector = lipgloss.NewStyle(). - Width(1). - Foreground(lipgloss.Color("#B083EA")) + Foreground(lipgloss.Color("#B083EA")). + SetString("> ") - s.RefItemActive = lipgloss.NewStyle(). - MarginLeft(1). - Bold(true) + s.RefItemActive = s.RefItemActive.Copy(). + Foreground(highlightColorDim) s.RefItemBranch = lipgloss.NewStyle() - s.RefItemTag = lipgloss.NewStyle(). + s.RefItemTagInactive = lipgloss.NewStyle(). Foreground(lipgloss.Color("#A3A322")) + s.RefItemTagActive = lipgloss.NewStyle(). + Bold(true). + Foreground(highlightColor) + + s.RefItemActive = lipgloss.NewStyle(). + Bold(true). + Foreground(highlightColor) + s.RefPaginator = s.LogPaginator.Copy() s.TreeItemSelector = s.TreeItemInactive.Copy().