MCPcopy Create free account
hub / github.com/cli/cli / printHumanView

Function printHumanView

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

Source from the content-addressed store, hash-verified

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