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

Function printHumanComment

pkg/cmd/discussion/view/view.go:493–593  ·  view source on GitHub ↗
(opts *ViewOptions, out io.Writer, c client.DiscussionComment, indent string, isReply bool, isNewest bool)

Source from the content-addressed store, hash-verified

491}
492
493func printHumanComment(opts *ViewOptions, out io.Writer, c client.DiscussionComment, indent string, isReply bool, isNewest bool) error {
494 cs := opts.IO.ColorScheme()
495 now := opts.Now()
496
497 action := "commented"
498 if isReply {
499 action = "replied"
500 }
501
502 header := fmt.Sprintf("%s%s %s • %s",
503 indent,
504 cs.Bold(c.Author.Login),
505 action,
506 text.FuzzyAgoAbbr(now, c.CreatedAt),
507 )
508 if c.IsAnswer {
509 header += fmt.Sprintf(" • %s %s", cs.SuccessIcon(), cs.Green("Answer"))
510 }
511 if isNewest {
512 kind := "comment"
513 if isReply {
514 kind = "reply"
515 }
516 header += fmt.Sprintf(" • %s", fmt.Sprintf(cs.CyanBold("Newest %s"), kind))
517 }
518 fmt.Fprintln(out, header)
519
520 if c.Body != "" {
521 md, err := markdown.Render(c.Body,
522 markdown.WithTheme(opts.IO.TerminalTheme()),
523 markdown.WithWrap(opts.IO.TerminalWidth()))
524 if err != nil {
525 return err
526 }
527 if indent != "" {
528 md = text.Indent(md, indent)
529 }
530 fmt.Fprint(out, md)
531 }
532
533 if reactions := reactionGroupList(c.ReactionGroups); reactions != "" {
534 fmt.Fprintf(out, "%s%s\n", indent, reactions)
535 }
536
537 fmt.Fprintln(out)
538
539 if isReply {
540 // Replies are leaf nodes, so there won't be children replies/comments.
541 return nil
542 }
543
544 if len(c.Replies.Comments) == 0 {
545 return nil
546 }
547
548 if c.Replies.Direction == client.DiscussionCommentListDirectionBackward {
549 if shown := len(c.Replies.Comments); shown < c.Replies.TotalCount {
550 remaining := c.Replies.TotalCount - shown

Callers 2

printHumanViewFunction · 0.85

Calls 15

FuzzyAgoAbbrFunction · 0.92
RenderFunction · 0.92
WithThemeFunction · 0.92
WithWrapFunction · 0.92
IndentFunction · 0.92
reactionGroupListFunction · 0.85
ColorSchemeMethod · 0.80
BoldMethod · 0.80
SuccessIconMethod · 0.80
GreenMethod · 0.80
CyanBoldMethod · 0.80
TerminalThemeMethod · 0.80

Tested by

no test coverage detected