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

Function displayResults

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

Source from the content-addressed store, hash-verified

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