MCPcopy
hub / github.com/cli/cli / printHumanView

Function printHumanView

pkg/cmd/discussion/view/view.go:336–451  ·  view source on GitHub ↗
(opts *ViewOptions, d *client.Discussion)

Source from the content-addressed store, hash-verified

334}
335
336func printHumanView(opts *ViewOptions, d *client.Discussion) error {
337 out := opts.IO.Out
338 cs := opts.IO.ColorScheme()
339
340 numberStr := fmt.Sprintf("#%d", d.Number)
341 if !d.Closed {
342 numberStr = cs.Green(numberStr)
343 } else {
344 numberStr = cs.Muted(numberStr)
345 }
346 fmt.Fprintf(out, "%s %s\n", cs.Bold(d.Title), numberStr)
347
348 state := "Open"
349 stateColor := cs.Green
350 if d.Closed {
351 state = "Closed"
352 stateColor = cs.Muted
353 }
354
355 verb := "Started by"
356 if d.Category.IsAnswerable {
357 verb = "Asked by"
358 }
359
360 fmt.Fprintf(out, "%s • %s • %s %s • %s • %s\n",
361 stateColor(state),
362 d.Category.Name,
363 verb,
364 d.Author.Login,
365 text.FuzzyAgo(opts.Now(), d.CreatedAt),
366 text.Pluralize(d.Comments.TotalCount, "comment"),
367 )
368
369 if labels := labelList(d.Labels, cs); labels != "" {
370 fmt.Fprint(out, cs.Bold("Labels: "))
371 fmt.Fprintln(out, labels)
372 }
373
374 var md string
375 if d.Body == "" {
376 md = fmt.Sprintf("\n %s\n\n", cs.Muted("No description provided"))
377 } else {
378 var err error
379 md, err = markdown.Render(d.Body,
380 markdown.WithTheme(opts.IO.TerminalTheme()),
381 markdown.WithWrap(opts.IO.TerminalWidth()))
382 if err != nil {
383 return err
384 }
385 }
386 fmt.Fprintf(out, "\n%s\n", md)
387
388 if reactions := reactionGroupList(d.ReactionGroups); reactions != "" {
389 fmt.Fprintln(out, reactions)
390 fmt.Fprintln(out)
391 }
392
393 // Comments section

Callers 1

viewRunFunction · 0.85

Calls 15

FuzzyAgoFunction · 0.92
PluralizeFunction · 0.92
RenderFunction · 0.92
WithThemeFunction · 0.92
WithWrapFunction · 0.92
labelListFunction · 0.85
reactionGroupListFunction · 0.85
printHumanCommentFunction · 0.85
ColorSchemeMethod · 0.80
GreenMethod · 0.80
MutedMethod · 0.80
BoldMethod · 0.80

Tested by

no test coverage detected