renderAllFiles dumps the tree, SKILL.md, and all extra files through the pager.
(opts *PreviewOptions, cs *iostreams.ColorScheme, skill discovery.Skill, files []discovery.SkillFile, rendered string, extraFiles []discovery.SkillFile, apiClient *api.Client, hostname, owner, repo string)
| 265 | |
| 266 | // renderAllFiles dumps the tree, SKILL.md, and all extra files through the pager. |
| 267 | func renderAllFiles(opts *PreviewOptions, cs *iostreams.ColorScheme, skill discovery.Skill, |
| 268 | files []discovery.SkillFile, rendered string, extraFiles []discovery.SkillFile, |
| 269 | apiClient *api.Client, hostname, owner, repo string) { |
| 270 | |
| 271 | opts.IO.DetectTerminalTheme() |
| 272 | if err := opts.IO.StartPager(); err != nil { |
| 273 | fmt.Fprintf(opts.IO.ErrOut, "starting pager failed: %v\n", err) |
| 274 | } |
| 275 | defer opts.IO.StopPager() |
| 276 | |
| 277 | out := opts.IO.Out |
| 278 | |
| 279 | if len(files) > 0 { |
| 280 | fmt.Fprintf(out, "%s\n", cs.Bold(skill.DisplayName()+"/")) |
| 281 | renderFileTree(out, cs, files) |
| 282 | fmt.Fprintln(out) |
| 283 | } |
| 284 | |
| 285 | fmt.Fprintf(out, "%s\n\n", cs.Bold("── SKILL.md ──")) |
| 286 | fmt.Fprint(out, rendered) |
| 287 | |
| 288 | const maxFiles = 20 |
| 289 | const maxTotalBytes = 512 * 1024 |
| 290 | fetched := 0 |
| 291 | totalBytes := 0 |
| 292 | for _, f := range extraFiles { |
| 293 | if fetched >= maxFiles { |
| 294 | fmt.Fprintf(out, "\n%s\n", cs.Muted(fmt.Sprintf("(skipped remaining files, showing first %d)", maxFiles))) |
| 295 | break |
| 296 | } |
| 297 | if totalBytes+f.Size > maxTotalBytes { |
| 298 | fmt.Fprintf(out, "\n%s\n", cs.Muted("(skipped remaining files, size limit reached)")) |
| 299 | break |
| 300 | } |
| 301 | fileContent, fetchErr := discovery.FetchBlob(apiClient, hostname, owner, repo, f.SHA) |
| 302 | if fetchErr != nil { |
| 303 | fmt.Fprintf(out, "\n%s\n\n%s\n", cs.Bold("── "+f.Path+" ──"), cs.Muted("(could not fetch file)")) |
| 304 | continue |
| 305 | } |
| 306 | fetched++ |
| 307 | totalBytes += len(fileContent) |
| 308 | fmt.Fprintf(out, "\n%s\n\n", cs.Bold("── "+f.Path+" ──")) |
| 309 | fmt.Fprint(out, fileContent) |
| 310 | if !strings.HasSuffix(fileContent, "\n") { |
| 311 | fmt.Fprintln(out) |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | // renderInteractive shows the file tree, then a picker to browse individual files. |
| 317 | func renderInteractive(opts *PreviewOptions, cs *iostreams.ColorScheme, skill discovery.Skill, |
no test coverage detected