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

Function printHumanView

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

Source from the content-addressed store, hash-verified

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