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