Skip to content

Commit

Permalink
Update color styling for year highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
bensadeh committed Dec 24, 2021
1 parent 4fc880f commit 2a019bc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion comment/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func highlightTitle(title string, highlightHeadlines bool) string {

if highlightHeadlines {
highlightedTitle = syntax.HighlightYCStartupsInHeadlines(title)
highlightedTitle = syntax.HighlightYearsInHeadlines(title)
highlightedTitle = syntax.HighlightYearInHeadlines(title)
highlightedTitle = syntax.HighlightHackerNewsHeadlines(highlightedTitle)
highlightedTitle = syntax.HighlightSpecialContent(highlightedTitle)
}
Expand Down
16 changes: 9 additions & 7 deletions syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ func HighlightYCStartupsInHeadlines(comment string) string {
return expression.ReplaceAllString(comment, highlightedStartup)
}

func HighlightYearsInHeadlines(comment string) string {
func HighlightYearInHeadlines(comment string) string {
expression := regexp.MustCompile(`\((\d{4})\)`)

highlightedStartup := Magenta(`$1`).String() + bold
background := uint8(238)
foreground := uint8(3)
highlightedYear := Index(foreground, ` $1 `).BgIndex(background).String() + bold

return expression.ReplaceAllString(comment, highlightedStartup)
return expression.ReplaceAllString(comment, highlightedYear)
}

func HighlightHackerNewsHeadlines(title string) string {
Expand All @@ -58,10 +60,10 @@ func HighlightHackerNewsHeadlines(title string) string {
}

func HighlightSpecialContent(title string) string {
title = strings.ReplaceAll(title, "[audio]", Yellow("audio").String())
title = strings.ReplaceAll(title, "[video]", Yellow("video").String())
title = strings.ReplaceAll(title, "[pdf]", Yellow("pdf").String())
title = strings.ReplaceAll(title, "[PDF]", Yellow("PDF").String())
title = strings.ReplaceAll(title, "[audio]", Cyan("audio").String())
title = strings.ReplaceAll(title, "[video]", Cyan("video").String())
title = strings.ReplaceAll(title, "[pdf]", Cyan("pdf").String())
title = strings.ReplaceAll(title, "[PDF]", Cyan("PDF").String())
title = strings.ReplaceAll(title, "[flagged]", Red("flagged").String())

return title
Expand Down
12 changes: 6 additions & 6 deletions title/title.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ func highlightYear(title string) string {
expression := regexp.MustCompile(`\((\d{4})\)`)

firstHighlightGroup := `$1`
highlightedStartup := formatter.Magenta("" + firstHighlightGroup + "")
highlightedYear := formatter.Year(" " + firstHighlightGroup + " ")

return expression.ReplaceAllString(title, highlightedStartup)
return expression.ReplaceAllString(title, highlightedYear)
}

func highlightSpecialContent(title string) string {
title = strings.ReplaceAll(title, "[audio[]", formatter.Yellow("audio"))
title = strings.ReplaceAll(title, "[video[]", formatter.Yellow("video"))
title = strings.ReplaceAll(title, "[pdf[]", formatter.Yellow("pdf"))
title = strings.ReplaceAll(title, "[PDF[]", formatter.Yellow("PDF"))
title = strings.ReplaceAll(title, "[audio[]", formatter.Cyan("audio"))
title = strings.ReplaceAll(title, "[video[]", formatter.Cyan("video"))
title = strings.ReplaceAll(title, "[pdf[]", formatter.Cyan("pdf"))
title = strings.ReplaceAll(title, "[PDF[]", formatter.Cyan("PDF"))
title = strings.ReplaceAll(title, "[flagged[]", formatter.Red("flagged"))

return title
Expand Down
6 changes: 6 additions & 0 deletions utils/formatter/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func Reverse(text string) string {
return "[::r]" + text + resetStyle
}

func Year(text string) string {
return cview.TranslateANSI("\u001b[48;5;238m") +
cview.TranslateANSI("\u001B[38;5;3m") +
text + resetForegroundAndBackground
}

func BlackOnOrange(text string) string {
return "[#0c0c0c:#FFA500]" + text + resetForegroundAndBackground
}
Expand Down

0 comments on commit 2a019bc

Please sign in to comment.