From a054be839f5b34abd607fda993c291597e82126e Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 13 Jul 2022 17:29:29 -0700 Subject: [PATCH] chore: adjust highlight style in top level repo selector --- 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(-) diff --git a/ui/components/selector/selector.go b/ui/components/selector/selector.go index ed044990e6d76473d015bb7b2c93b5352408bc02..4beea1fe3e6ca934688c680bcebdeceaf9af6a73 100644 --- a/ui/components/selector/selector.go +++ b/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 diff --git a/ui/pages/selection/item.go b/ui/pages/selection/item.go index 8629add33afe730cc14fa87d5d2ef684007ef845..859ebdf4b7beb6e1cde110a2e0fddd446e257932 100644 --- a/ui/pages/selection/item.go +++ b/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())) } diff --git a/ui/pages/selection/selection.go b/ui/pages/selection/selection.go index 0e965a7f7006f2c51f9a5c08f199e93a61e00aba..01e3d52a2683931589dd55fb29bea4d0cfe4203a 100644 --- a/ui/pages/selection/selection.go +++ b/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 diff --git a/ui/styles/styles.go b/ui/styles/styles.go index 5b079bbfb0c20d7f1a36fef2b3ae16e3567aa220..55b4989d1229b6012f42c754ee537d7a3d047909 100644 --- a/ui/styles/styles.go +++ b/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{