MCPcopy
hub / github.com/cli/cli / displayResults

Function displayResults

pkg/cmd/search/code/code.go:163–190  ·  view source on GitHub ↗
(io *iostreams.IOStreams, results search.CodeResult)

Source from the content-addressed store, hash-verified

161}
162
163func displayResults(io *iostreams.IOStreams, results search.CodeResult) error {
164 cs := io.ColorScheme()
165 if io.IsStdoutTTY() {
166 fmt.Fprintf(io.Out, "\nShowing %d of %d results\n\n", len(results.Items), results.Total)
167 for i, code := range results.Items {
168 if i > 0 {
169 fmt.Fprint(io.Out, "\n")
170 }
171 fmt.Fprintf(io.Out, "%s %s\n", cs.Blue(code.Repository.FullName), cs.GreenBold(code.Path))
172 for _, match := range code.TextMatches {
173 lines := formatMatch(match.Fragment, match.Matches, io)
174 for _, line := range lines {
175 fmt.Fprintf(io.Out, "\t%s\n", strings.TrimSpace(line))
176 }
177 }
178 }
179 return nil
180 }
181 for _, code := range results.Items {
182 for _, match := range code.TextMatches {
183 lines := formatMatch(match.Fragment, match.Matches, io)
184 for _, line := range lines {
185 fmt.Fprintf(io.Out, "%s:%s: %s\n", cs.Blue(code.Repository.FullName), cs.GreenBold(code.Path), strings.TrimSpace(line))
186 }
187 }
188 }
189 return nil
190}
191
192func formatMatch(t string, matches []search.Match, io *iostreams.IOStreams) []string {
193 cs := io.ColorScheme()

Callers 1

codeRunFunction · 0.70

Calls 5

formatMatchFunction · 0.85
ColorSchemeMethod · 0.80
IsStdoutTTYMethod · 0.80
BlueMethod · 0.80
GreenBoldMethod · 0.80

Tested by

no test coverage detected