MCPcopy
hub / github.com/charmbracelet/glow / styleFilteredText

Function styleFilteredText

ui/stashitem.go:92–120  ·  view source on GitHub ↗
(haystack, needles string, defaultStyle, matchedStyle lipgloss.Style)

Source from the content-addressed store, hash-verified

90}
91
92func 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}

Callers 1

stashItemViewFunction · 0.85

Calls 3

normalizeFunction · 0.85
ErrorMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…