9210c7d595417b0b7142cfad0bf702ebe5658ca0

Author
Christian Rocha <christian@rocha.is>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

feat: apply highlight styling to log browser

Diff

  1diff --git a/ui/pages/repo/logitem.go b/ui/pages/repo/logitem.go
  2index f4c3fc6a4e4fe43a00cbebf2dd5e45fd47b04208..4382deadeb91a2c3f8024313fcba81e7e6887336 100644
  3--- a/ui/pages/repo/logitem.go
  4+++ b/ui/pages/repo/logitem.go
  5@@ -74,10 +74,6 @@ func (d LogItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
  6 	return nil
  7 }
  8 
  9-var (
 10-	faint = func(s string) string { return lipgloss.NewStyle().Faint(true).Render(s) }
 11-)
 12-
 13 // Render renders the item. Implements list.ItemDelegate.
 14 func (d LogItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
 15 	styles := d.common.Styles
 16@@ -89,17 +85,27 @@ func (d LogItemDelegate) Render(w io.Writer, m list.Model, index int, listItem l
 17 		return
 18 	}
 19 
 20-	titleStyle := styles.LogItemTitle.Copy()
 21+	var titleStyler,
 22+		descStyler,
 23+		keywordStyler func(string) string
 24 	style := styles.LogItemInactive
 25+
 26 	if index == m.Index() {
 27-		titleStyle.Bold(true)
 28+		titleStyler = styles.LogItemTitleActive.Render
 29+		descStyler = styles.LogItemDescActive.Render
 30+		keywordStyler = styles.LogItemKeywordActive.Render
 31 		style = styles.LogItemActive
 32+	} else {
 33+		titleStyler = styles.LogItemTitleInactive.Render
 34+		descStyler = styles.LogItemDescInactive.Render
 35+		keywordStyler = styles.LogItemKeywordInactive.Render
 36 	}
 37+
 38 	hash := i.Commit.ID.String()[:7]
 39 	if !i.copied.IsZero() && i.copied.Add(time.Second).After(time.Now()) {
 40 		hash = "copied"
 41 	}
 42-	title := titleStyle.Render(
 43+	title := titleStyler(
 44 		common.TruncateString(i.Title(),
 45 			m.Width()-
 46 				style.GetHorizontalFrameSize()-
 47@@ -119,27 +125,26 @@ func (d LogItemDelegate) Render(w io.Writer, m list.Model, index int, listItem l
 48 	hash = hashStyle.Render(hash)
 49 	if m.Width()-style.GetHorizontalFrameSize()-hashStyle.GetHorizontalFrameSize()-hashStyle.GetWidth() <= 0 {
 50 		hash = ""
 51-		title = titleStyle.Render(
 52+		title = titleStyler(
 53 			common.TruncateString(i.Title(),
 54 				m.Width()-style.GetHorizontalFrameSize()),
 55 		)
 56 	}
 57 	author := i.Author.Name
 58-	commiter := i.Committer.Name
 59+	committer := i.Committer.Name
 60 	who := ""
 61-	if author != "" && commiter != "" {
 62-		who = commiter + faint(" committed")
 63-		if author != commiter {
 64-			who = author + faint(" authored and ") + who
 65+	if author != "" && committer != "" {
 66+		who = keywordStyler(committer) + descStyler(" committed")
 67+		if author != committer {
 68+			who = keywordStyler(author) + descStyler(" authored and ") + who
 69 		}
 70 		who += " "
 71 	}
 72-	date := fmt.Sprintf("on %s", i.Committer.When.Format("Feb 02"))
 73-	date = faint(date)
 74+	date := i.Committer.When.Format("Feb 02")
 75 	if i.Committer.When.Year() != time.Now().Year() {
 76 		date += fmt.Sprintf(" %d", i.Committer.When.Year())
 77 	}
 78-	who += date
 79+	who += descStyler("on ") + keywordStyler(date)
 80 	who = common.TruncateString(who, m.Width()-style.GetHorizontalFrameSize())
 81 	fmt.Fprint(w,
 82 		style.Render(
 83diff --git a/ui/styles/styles.go b/ui/styles/styles.go
 84index b626158b12891ff3305af51b5479759bec4931f1..2790191f0a9672ca8c7fc245fa6aafcc7d16656a 100644
 85--- a/ui/styles/styles.go
 86+++ b/ui/styles/styles.go
 87@@ -44,20 +44,25 @@ type Styles struct {
 88 
 89 	AboutNoReadme lipgloss.Style
 90 
 91-	LogItem           lipgloss.Style
 92-	LogItemSelector   lipgloss.Style
 93-	LogItemActive     lipgloss.Style
 94-	LogItemInactive   lipgloss.Style
 95-	LogItemHash       lipgloss.Style
 96-	LogItemTitle      lipgloss.Style
 97-	LogCommit         lipgloss.Style
 98-	LogCommitHash     lipgloss.Style
 99-	LogCommitAuthor   lipgloss.Style
100-	LogCommitDate     lipgloss.Style
101-	LogCommitBody     lipgloss.Style
102-	LogCommitStatsAdd lipgloss.Style
103-	LogCommitStatsDel lipgloss.Style
104-	LogPaginator      lipgloss.Style
105+	LogItem                lipgloss.Style
106+	LogItemSelector        lipgloss.Style
107+	LogItemActive          lipgloss.Style
108+	LogItemInactive        lipgloss.Style
109+	LogItemHash            lipgloss.Style
110+	LogItemTitleInactive   lipgloss.Style
111+	LogItemTitleActive     lipgloss.Style
112+	LogItemDescInactive    lipgloss.Style
113+	LogItemDescActive      lipgloss.Style
114+	LogItemKeywordActive   lipgloss.Style
115+	LogItemKeywordInactive lipgloss.Style
116+	LogCommit              lipgloss.Style
117+	LogCommitHash          lipgloss.Style
118+	LogCommitAuthor        lipgloss.Style
119+	LogCommitDate          lipgloss.Style
120+	LogCommitBody          lipgloss.Style
121+	LogCommitStatsAdd      lipgloss.Style
122+	LogCommitStatsDel      lipgloss.Style
123+	LogPaginator           lipgloss.Style
124 
125 	RefItemSelector    lipgloss.Style
126 	RefItemActive      lipgloss.Style
127@@ -101,7 +106,7 @@ type Styles struct {
128 func DefaultStyles() *Styles {
129 	highlightColor := lipgloss.Color("210")
130 	highlightColorDim := lipgloss.Color("174")
131-	selectorColor := lipgloss.Color("204")
132+	selectorColor := lipgloss.Color("167")
133 
134 	s := new(Styles)
135 
136@@ -214,7 +219,7 @@ func DefaultStyles() *Styles {
137 		Border(lipgloss.Border{
138 			Left: "┃",
139 		}, false, false, false, true).
140-		BorderForeground(lipgloss.Color("#B083EA"))
141+		BorderForeground(selectorColor)
142 
143 	s.LogItemSelector = s.LogItemInactive.Copy().
144 		Width(1).
145@@ -223,9 +228,21 @@ func DefaultStyles() *Styles {
146 	s.LogItemHash = s.LogItemInactive.Copy().
147 		Foreground(lipgloss.Color("#A3A322"))
148 
149-	s.LogItemTitle = lipgloss.NewStyle().
150+	s.LogItemTitleInactive = lipgloss.NewStyle().
151 		Foreground(lipgloss.Color("#B083EA"))
152 
153+	s.LogItemTitleActive = lipgloss.NewStyle().
154+		Foreground(highlightColor).
155+		Bold(true)
156+
157+	s.LogItemDescInactive = lipgloss.NewStyle()
158+
159+	s.LogItemDescActive = lipgloss.NewStyle().
160+		Foreground(lipgloss.Color("95"))
161+
162+	s.LogItemKeywordActive = s.LogItemDescActive.Copy().
163+		Foreground(highlightColorDim)
164+
165 	s.LogCommit = lipgloss.NewStyle().
166 		Margin(0, 2)
167