Skip to content

Commit

Permalink
highlight exact match strings in search
Browse files Browse the repository at this point in the history
  • Loading branch information
hay-kot committed Aug 9, 2022
1 parent f43ada4 commit 91130bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions tui/fuzzyfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,13 @@ func (m fuzzyFinderView) View() string {

m.ctrl.limit = determinedMax

str.WriteString(
m.search.View(),
)

if m.ctrl.selected > m.ctrl.limit {
m.ctrl.selected = 0
}

str.WriteString(m.search.View())
str.WriteString(ui.Subtle(fmt.Sprintf("\n %d/%d", len(results), len(m.ctrl.matches))) + "\n")
str.WriteString(m.fmtMatches(results[:determinedMax]))

return str.String()
}

Expand All @@ -207,6 +203,8 @@ func (m fuzzyFinderView) fmtMatches(repos []gofind.Match) string {
}
}

search := m.search.Value()

str := strings.Builder{}
for i, repo := range repos {
spaces := (longest + 5) - len(repo.Name)
Expand All @@ -216,6 +214,11 @@ func (m fuzzyFinderView) fmtMatches(repos []gofind.Match) string {
if m.ctrl.selected == i {
prefix = ui.HighlightRow(ui.AccentRed(">"))
text = ui.HighlightRow(ui.Bold(text))
} else {
if search != "" && strings.Contains(repo.Name, search) {
// Highlight the search term
text = strings.ReplaceAll(text, search, ui.Bold(search))
}
}

str.WriteString(prefix + text + "\n")
Expand Down
6 changes: 4 additions & 2 deletions ui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package ui

import "github.com/charmbracelet/lipgloss"

var (
const (
ColorBlue = lipgloss.Color("#255F85")
ColorRed = lipgloss.Color("#DA4167")
ColorSubtle = lipgloss.Color("#848484")
ColorWhite = lipgloss.Color("#FFFFFF")
)

var (
Bold = lipgloss.NewStyle().Bold(true).Render
Bold = lipgloss.NewStyle().Bold(true).Foreground(ColorWhite).Render
Subtle = lipgloss.NewStyle().Foreground(ColorSubtle).Render
AccentRed = lipgloss.NewStyle().Foreground(ColorRed).Render
AccentBlue = lipgloss.NewStyle().Foreground(ColorBlue).Render
Expand Down

0 comments on commit 91130bb

Please sign in to comment.