(haystack, needles string, defaultStyle, matchedStyle lipgloss.Style)
| 90 | } |
| 91 | |
| 92 | func styleFilteredText(haystack, needles string, defaultStyle, matchedStyle lipgloss.Style) string { |
| 93 | b := strings.Builder{} |
| 94 | |
| 95 | normalizedHay, err := normalize(haystack) |
| 96 | if err != nil { |
| 97 | log.Error("error normalizing", "haystack", haystack, "error", err) |
| 98 | } |
| 99 | |
| 100 | matches := fuzzy.Find(needles, []string{normalizedHay}) |
| 101 | if len(matches) == 0 { |
| 102 | return defaultStyle.Render(haystack) |
| 103 | } |
| 104 | |
| 105 | m := matches[0] // only one match exists |
| 106 | for i, rune := range []rune(haystack) { |
| 107 | styled := false |
| 108 | for _, mi := range m.MatchedIndexes { |
| 109 | if i == mi { |
| 110 | b.WriteString(matchedStyle.Render(string(rune))) |
| 111 | styled = true |
| 112 | } |
| 113 | } |
| 114 | if !styled { |
| 115 | b.WriteString(defaultStyle.Render(string(rune))) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return b.String() |
| 120 | } |
no test coverage detected
searching dependent graphs…