(t string, matches []search.Match, io *iostreams.IOStreams)
| 190 | } |
| 191 | |
| 192 | func formatMatch(t string, matches []search.Match, io *iostreams.IOStreams) []string { |
| 193 | cs := io.ColorScheme() |
| 194 | |
| 195 | startIndices := map[int]struct{}{} |
| 196 | endIndices := map[int]struct{}{} |
| 197 | for _, m := range matches { |
| 198 | if len(m.Indices) < 2 { |
| 199 | continue |
| 200 | } |
| 201 | startIndices[m.Indices[0]] = struct{}{} |
| 202 | endIndices[m.Indices[1]] = struct{}{} |
| 203 | } |
| 204 | |
| 205 | var lines []string |
| 206 | var b strings.Builder |
| 207 | var found bool |
| 208 | for i, c := range t { |
| 209 | if c == '\n' { |
| 210 | if found { |
| 211 | lines = append(lines, b.String()) |
| 212 | } |
| 213 | found = false |
| 214 | b.Reset() |
| 215 | continue |
| 216 | } |
| 217 | if _, ok := startIndices[i]; ok { |
| 218 | b.WriteString(cs.HighlightStart()) |
| 219 | found = true |
| 220 | } else if _, ok := endIndices[i]; ok { |
| 221 | b.WriteString(cs.Reset()) |
| 222 | } |
| 223 | b.WriteRune(c) |
| 224 | } |
| 225 | if found { |
| 226 | lines = append(lines, b.String()) |
| 227 | } |
| 228 | return lines |
| 229 | } |
no test coverage detected